HTTP状态code。与libcurl的? [英] Http status code with libcurl?

查看:1001
本文介绍了HTTP状态code。与libcurl的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么呼唤curl_easy_perform后,HTTP状态code(如200或500)?

How do I get the HTTP status code (eg 200 or 500) after calling curl_easy_perform?

推荐答案

<一个href=\"http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html\">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
}

这篇关于HTTP状态code。与libcurl的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆