c - 带有 libcurl 的 HTTP 状态代码?

标签 c http libcurl

如何在调用 curl_easy_perform 后获取 HTTP 状态代码(例如 200 或 500)?

最佳答案

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
}

关于c - 带有 libcurl 的 HTTP 状态代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/290996/

相关文章:

c - if () 语句的不同参数

php - 在 PHP 中创建一个网络服务器(没有 Apache)

java - 在 Spring 中解析 Multipart/mixed

c - vcpkg curl 端口不支持 FTP?

libcurl.so.4 : cannot open shared object file: No such file or directory

c - C 编译器不采用 5/9 来计算 fc

Sqlite API bool 访问

java - 面向对象语言和非面向对象语言有什么区别?

php - 如何防止我的网站使用 php 在 iframe 中加载

c++ - libcurl http post 将数据发送到服务器