Пример #1
0
PCS_API PcsBool pcs_http_get_download(PcsHttp handle, const char *url, PcsBool follow_location, curl_off_t max_speed, curl_off_t resume_from, curl_off_t max_length)
{
	struct pcs_http *http = (struct pcs_http *)handle;
	pcs_http_prepare(http, HTTP_METHOD_GET, url, follow_location, &pcs_http_write, http, max_speed, resume_from, max_length);
	http->res_type = PCS_HTTP_RES_TYPE_DOWNLOAD;
	pcs_http_perform(http, url);
	return http->strerror == NULL ? PcsTrue : PcsFalse;
}
Пример #2
0
PCS_API char *pcs_http_post(PcsHttp handle, const char *url, char *post_data, PcsBool follow_location)
{
	struct pcs_http *http = (struct pcs_http *)handle;
	pcs_http_prepare(http, HTTP_METHOD_POST, url, follow_location, &pcs_http_write, http, 0, 0, 0, 0);
	if (post_data)
		curl_easy_setopt(http->curl, CURLOPT_POSTFIELDS, post_data);  
	else
		curl_easy_setopt(http->curl, CURLOPT_POSTFIELDS, "");  
	return pcs_http_perform(http, url);
}
Пример #3
0
PCS_API char *pcs_http_get_raw(PcsHttp handle, const char *url, PcsBool follow_location, size_t *sz)
{
	struct pcs_http *http = (struct pcs_http *)handle;
	char *data;
	pcs_http_prepare(http, HTTP_METHOD_GET, url, follow_location, &pcs_http_write, http, 0, 0, 0, 0);
	http->res_type = PCS_HTTP_RES_TYPE_RAW;
	data = pcs_http_perform(http, url);
	if (sz) *sz = http->res_body_size;
	return data;
}
Пример #4
0
PCS_API char *pcs_post_httpform(PcsHttp handle, const char *url, PcsHttpForm data, PcsBool follow_location)
{
	struct pcs_http *http = (struct pcs_http *)handle;
	struct http_post *formpost = (struct http_post *)data;
	pcs_http_prepare(http, HTTP_METHOD_POST, url, follow_location, &pcs_http_write, http);
	if (data)
		curl_easy_setopt(http->curl, CURLOPT_HTTPPOST, formpost->formpost); 
	else
		curl_easy_setopt(http->curl, CURLOPT_POSTFIELDS, "");  
	return pcs_http_perform(http);
}
Пример #5
0
PCS_API int64_t pcs_http_get_download_filesize(PcsHttp handle, const char *url, PcsBool follow_location)
{
	CURLcode res;
	double downloadFileLenth = 0;
	struct pcs_http *http = (struct pcs_http *)handle;
	pcs_http_prepare(http, HTTP_METHOD_GET, url, follow_location, pcs_http_null_write, NULL, 0, 0, 0, 0);
	curl_easy_setopt(http->curl, CURLOPT_NOBODY, 1L);   //不需要body
	res = curl_easy_perform(http->curl);
	if (res == CURLE_OK) {
		curl_easy_getinfo(http->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &downloadFileLenth);
	}
	else {
		if (!http->strerror) http->strerror = pcs_utils_strdup(curl_easy_strerror(res));
		downloadFileLenth = 0;
	}
	return (int64_t)downloadFileLenth;
}
Пример #6
0
PCS_API char *pcs_post_httpform(PcsHttp handle, const char *url, PcsHttpForm data, curl_off_t max_speed, PcsBool follow_location)
{
	struct pcs_http *http = (struct pcs_http *)handle;
	struct http_post *formpost = (struct http_post *)data;
	char *rc;
	pcs_http_prepare(http, HTTP_METHOD_POST, url, follow_location, &pcs_http_write, http, 0, max_speed, 0, 0);
	if (data){
		curl_easy_setopt(http->curl, CURLOPT_HTTPPOST, formpost->formpost); 
		if (formpost->read_func) {
			curl_easy_setopt(http->curl, CURLOPT_READFUNCTION, formpost->read_func);
			curl_easy_setopt(http->curl, CURLOPT_READDATA, formpost->read_func_data);
		}
	}
	else
		curl_easy_setopt(http->curl, CURLOPT_POSTFIELDS, "");  
	rc = pcs_http_perform(http, url);
	if (data && formpost->read_func) {
		curl_easy_setopt(http->curl, CURLOPT_READFUNCTION, NULL);
		curl_easy_setopt(http->curl, CURLOPT_READDATA, NULL);
	}
	return rc;
}
Пример #7
0
PCS_API char *pcs_http_get(PcsHttp handle, const char *url, PcsBool follow_location)
{
	struct pcs_http *http = (struct pcs_http *)handle;
	pcs_http_prepare(http, HTTP_METHOD_GET, url, follow_location, &pcs_http_write, http, 0, 0, 0, 0);
	return pcs_http_perform(http, url);
}