2015-09-15 106 views
-1

我在某些客戶端計算機上遇到捲曲請求問題。儘管http請求在瀏覽器和大多數win 7 64位sp1機器上都能正常工作,但它在某些用戶機器上失敗。 您的輸入是欣賞。這是使用curl的代碼存根。捲曲錯誤代碼7

謝謝

bool HttpClient::request(const ArStr& url, HttpBuffer& header, HttpBuffer& body, unsigned long& status, ArStr& contentEncoding 
    , bool bFollowRedirect /*= true*/, bool bForceNoCache /*= false*/, bool bForceNoCookie /*= true*/) 
{ 
    try 
    { 
     bool ret = false; 

     CURL *curl_handle; 

     /* init the curl session */ 
     curl_handle = curl_easy_init(); 
     if (curl_handle == NULL) 
     { 
      Logger::Instance()->Error(_T("Failed to init curl")); 
      return ret; 
     } 

     curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1); 

     curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str()); 

     unsigned long nConnectTimeout = _nConnectTimeout; 

     if (bFollowRedirect) 
      curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); 

     if (bForceNoCookie) 
      curl_easy_setopt(curl_handle, CURLOPT_COOKIESESSION, 1); // Set this value to ensure the session does not reuse old cookie, by default it is 0 

     if (bForceNoCache) 
      curl_easy_setopt(curl_handle, CURLOPT_FRESH_CONNECT, 1); // By default it is 0 

     //add proxy setting with scheme 

     char strProxy[1024] = { 0 }; 
     curl_easy_setopt(curl_handle, CURLOPT_PROXYPORT, strProxy); 

     curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT_MS, &nConnectTimeout); 

     unsigned long nTimeout = max(_nReceiveTimeout, _nSendTimeout); 
     curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT_MS, &nTimeout); 
     struct curl_slist *list = NULL; 
     list = curl_slist_append(list, "Test: data"); 
     curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, list); 
     /* no progress meter please */ 
     curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1); 

     /* send all data to this function */ 
     curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data); 

     curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, &header); 

     curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &body); 

     curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L); 
     curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L); 
     curl_easy_setopt(curl_handle, CURLOPT_DEBUGFUNCTION, debug_callback); 
     curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1); // For outputing debug information 
     curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L); 
     /* get it! */ 
     CURLcode res = CURLE_OK; 
     try 
     { 
      res = curl_easy_perform(curl_handle); 
     } 
     catch (exception ex) 
     { 
      Logger::Instance()->Error(_T("Failed to post data to %s, exception: %s"), url.c_str(), ex.what()); 
      res = CURLE_HTTP_POST_ERROR; 
     } 
     Logger::Instance()->Info(_T("status %d"), status); 
     Logger::Instance()->Info(_T("curl result %d"), res); 

     curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &status); 

     char *ct; 
     curl_easy_getinfo(curl_handle, CURLINFO_CONTENT_TYPE, &ct); 
     if (ct != NULL) 
      contentEncoding = Utils::StringToArStr(ct); 

     _lastInetErrorCode = res; 

     if (res != CURLE_OK) 
     { 
      Logger::Instance()->Error(_T("Failed to send HTTP request, error code: %d"), res); 
      ret = false; 
     } 
     else 
     { 
      ret = true; 
     } 

     /* cleanup curl stuff */ 
     curl_easy_cleanup(curl_handle); 

     return ret; 
    } 
    catch (exception ex) 
    { 
     Logger::Instance()->Error(_T("Failed to send http request"), ex.what()); 
    } 
} 

回答

1

List of return codes of cURL

CURLE_COULDNT_CONNECT(7)

無法連接()到主機或代理。

+0

我已經擡頭此錯誤代碼。但它爲什麼失敗(在瀏覽器中的http請求的工作) –

+0

@PriyaRajput防火牆?網絡超時?同一個私人網絡?一些奇怪的窗口安全? –