代码之家  ›  专栏  ›  技术社区  ›  twk Mark Adler

带libcurl的Http状态代码?

  •  84
  • twk Mark Adler  · 技术社区  · 16 年前

    2 回复  |  直到 12 年前
        1
  •  143
  •   Vinko Vrsalovic    16 年前

    http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html

    CURLINFO_RESPONSE_CODE
    
    Pass a pointer to a long to receive the last received HTTP or FTP code. This
    option was known as CURLINFO_HTTP_CODE in libcurl 7.10.7 and earlier. This 
    will be zero if no server response code has been received. Note that a 
    proxy's CONNECT response should be read with CURLINFO_HTTP_CONNECTCODE 
    and not this. 
    
    curl_code = curl_easy_perform (session);
    long http_code = 0;
    curl_easy_getinfo (session, CURLINFO_RESPONSE_CODE, &http_code);
    if (http_code == 200 && curl_code != CURLE_ABORTED_BY_CALLBACK)
    {
             //Succeeded
    }
    else
    {
             //Failed
    }
    
        2
  •  10
  •   kralyk    7 年前

    另一个答案是绝对正确的,但我还想补充一点,手工检查错误代码可能不是明智之举 200

    CURLOPT_FAILONERROR 当被激活时会考虑 400 500 -类别状态为请求失败,不会返回 CURLE_OK