|
|
@@ -57,7 +57,7 @@ static size_t OnWriteData(void* buffer, size_t size, size_t nmemb, void* lpVoid)
|
|
|
return nmemb;
|
|
|
}
|
|
|
|
|
|
-int CHttpClient::Post(const std::string & strUrl, const std::string & strPost, std::string & strResponse, CZhipuziHttpProxy proxy)
|
|
|
+int CHttpClient::Post(const std::string & strUrl, const std::string & strPost, std::string & strResponse, CZhipuziHttpProxy proxy, int timeout)
|
|
|
{
|
|
|
CURLcode res;
|
|
|
CURL* curl = curl_easy_init();
|
|
|
@@ -93,14 +93,14 @@ int CHttpClient::Post(const std::string & strUrl, const std::string & strPost, s
|
|
|
}
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
|
|
- curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 8);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
|
|
|
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
|
|
|
+ curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
|
|
|
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
|
|
|
res = curl_easy_perform(curl);
|
|
|
curl_easy_cleanup(curl);
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
-int CHttpClient::Get(const std::string & strUrl, std::string & strResponse, CZhipuziHttpProxy proxy)
|
|
|
+int CHttpClient::Get(const std::string & strUrl, std::string & strResponse, CZhipuziHttpProxy proxy, int timeout)
|
|
|
{
|
|
|
CURLcode res;
|
|
|
CURL* curl = curl_easy_init();
|
|
|
@@ -138,8 +138,8 @@ int CHttpClient::Get(const std::string & strUrl, std::string & strResponse, CZhi
|
|
|
* 如果不设置这个选项,libcurl将会发信号打断这个wait从而导致程序退出。
|
|
|
*/
|
|
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
|
|
- curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 8);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
|
|
|
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
|
|
|
+ curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
|
|
|
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
|
|
|
res = curl_easy_perform(curl);
|
|
|
curl_easy_cleanup(curl);
|
|
|
return res;
|
|
|
@@ -148,7 +148,7 @@ int CHttpClient::Get(const std::string & strUrl, std::string & strResponse, CZhi
|
|
|
/*
|
|
|
*返回值说明 https://blog.csdn.net/u011857683/article/details/53069268
|
|
|
**/
|
|
|
-int CHttpClient::Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath, CZhipuziHttpProxy proxy)
|
|
|
+int CHttpClient::Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath, CZhipuziHttpProxy proxy, int timeout)
|
|
|
{
|
|
|
CURLcode res;
|
|
|
CURL* curl = curl_easy_init();
|
|
|
@@ -200,14 +200,14 @@ int CHttpClient::Posts(const std::string & strUrl, const std::string & strPost,
|
|
|
curl_easy_setopt(curl, CURLOPT_CAINFO, pCaPath);
|
|
|
}
|
|
|
|
|
|
- curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 8);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
|
|
|
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
|
|
|
+ curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
|
|
|
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
|
|
|
res = curl_easy_perform(curl);
|
|
|
curl_easy_cleanup(curl);
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
-int CHttpClient::Gets(const std::string & strUrl, std::string & strResponse, const char * pCaPath, CZhipuziHttpProxy proxy)
|
|
|
+int CHttpClient::Gets(const std::string & strUrl, std::string & strResponse, const char * pCaPath, CZhipuziHttpProxy proxy, int timeout)
|
|
|
{
|
|
|
CURLcode res;
|
|
|
CURL* curl = curl_easy_init();
|
|
|
@@ -254,8 +254,8 @@ int CHttpClient::Gets(const std::string & strUrl, std::string & strResponse, con
|
|
|
curl_easy_setopt(curl, CURLOPT_CAINFO, pCaPath);
|
|
|
}
|
|
|
|
|
|
- curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 8);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
|
|
|
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
|
|
|
+ curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
|
|
|
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
|
|
|
res = curl_easy_perform(curl);
|
|
|
curl_easy_cleanup(curl);
|
|
|
return res;
|