|
|
@@ -182,7 +182,7 @@ bool CurlHttp::Post(const std::string& url, const std::string& postData, std::st
|
|
|
/* 设置重定向,遇到3xx返回值时自动重定向 */
|
|
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
|
|
/* 设置https协议 */
|
|
|
- curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
|
|
|
+ curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "http");
|
|
|
|
|
|
/* 设置包体 */
|
|
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postData.c_str());
|
|
|
@@ -228,6 +228,10 @@ bool CurlHttp::Post(const std::string& url, const std::string& postData, std::st
|
|
|
*/
|
|
|
bool CurlHttp::Post(const std::string& url,const std::vector<std::string>& vecHeader, const std::string& postData, std::string& response)
|
|
|
{
|
|
|
+ if(url.size() < 8)
|
|
|
+ {
|
|
|
+ FMTLOG_ERROR("url error, url size less 8");
|
|
|
+ }
|
|
|
CURL *curl;
|
|
|
CURLcode res;
|
|
|
curl = curl_easy_init();
|
|
|
@@ -241,8 +245,17 @@ bool CurlHttp::Post(const std::string& url,const std::vector<std::string>& vecHe
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
|
|
/* 设置重定向,遇到3xx返回值时自动重定向 */
|
|
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
|
|
- /* 设置https协议 */
|
|
|
- curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
|
|
|
+ /* 设置https协议,自动判断是http还是https */
|
|
|
+ std::string strUrlPre;
|
|
|
+ if(url.rfind("http://", 0) == 0)
|
|
|
+ {
|
|
|
+ strUrlPre = "http";
|
|
|
+ }
|
|
|
+ else if(url.rfind("https://", 0) == 0)
|
|
|
+ {
|
|
|
+ strUrlPre = "https";
|
|
|
+ }
|
|
|
+ curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, strUrlPre.c_str());
|
|
|
|
|
|
/* 设置http头 */
|
|
|
struct curl_slist *headers = NULL;
|