//执行设置好的操作 res = curl_easy_perform(easy_handle); //获取HTTP错误码 long HTTP_flag = 0; curl_easy_getinfo(easy_handle, CURLINFO_RESPONSE_CODE, &HTTP_flag);
curl_getinfo
(PHP 4 >= 4.0.4, PHP 5, PHP 7)
curl_getinfo — 获取一个cURL连接资源句柄的信息
参数
ch
-
由 curl_init() 返回的 cURL 句柄。
opt
-
这个参数可能是以下常量之一:
CURLINFO_EFFECTIVE_URL
- 最后一个有效的URL地址CURLINFO_HTTP_CODE
- 最后一个收到的HTTP代码CURLINFO_FILETIME
- 远程获取文档的时间,如果无法获取,则返回值为“-1”CURLINFO_TOTAL_TIME
- 最后一次传输所消耗的时间CURLINFO_NAMELOOKUP_TIME
- 名称解析所消耗的时间CURLINFO_CONNECT_TIME
- 建立连接所消耗的时间CURLINFO_PRETRANSFER_TIME
- 从建立连接到准备传输所使用的时间CURLINFO_STARTTRANSFER_TIME
- 从建立连接到传输开始所使用的时间CURLINFO_REDIRECT_TIME
- 在事务传输开始前重定向所使用的时间CURLINFO_SIZE_UPLOAD
- 以字节为单位返回上传数据量的总值CURLINFO_SIZE_DOWNLOAD
- 以字节为单位返回下载数据量的总值CURLINFO_SPEED_DOWNLOAD
- 平均下载速度CURLINFO_SPEED_UPLOAD
- 平均上传速度CURLINFO_HEADER_SIZE
- header部分的大小CURLINFO_HEADER_OUT
- 发送请求的字符串CURLINFO_REQUEST_SIZE
- 在HTTP请求中有问题的请求的大小CURLINFO_SSL_VERIFYRESULT
- 通过设置CURLOPT_SSL_VERIFYPEER
返回的SSL证书验证请求的结果CURLINFO_CONTENT_LENGTH_DOWNLOAD
- 从Content-Length: field中读取的下载内容长度CURLINFO_CONTENT_LENGTH_UPLOAD
- 上传内容大小的说明CURLINFO_CONTENT_TYPE
- 下载内容的Content-Type:值,NULL表示服务器没有发送有效的Content-Type:header
返回值
如果 opt
被设置,以字符串形式返回它的值。否则,返回返回一个包含下列元素的关联数组(它们分别对应于 opt
):
- "url"
- "content_type"
- "http_code"
- "header_size"
- "request_size"
- "filetime"
- "ssl_verify_result"
- "redirect_count"
- "total_time"
- "namelookup_time"
- "connect_time"
- "pretransfer_time"
- "size_upload"
- "size_download"
- "speed_download"
- "speed_upload"
- "download_content_length"
- "upload_content_length"
- "starttransfer_time"
- "redirect_time"
Here are the response codes ready for pasting in an ini-style file. Can be used to provide more descriptive message, corresponding to 'http_code' index of the arrray returned by curl_getinfo().
These are taken from the W3 consortium HTTP/1.1: Status Code Definitions, found at
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
[Informational 1xx]
100="Continue"
101="Switching Protocols"
[Successful 2xx]
200="OK"
201="Created"
202="Accepted"
203="Non-Authoritative Information"
204="No Content"
205="Reset Content"
206="Partial Content"
[Redirection 3xx]
300="Multiple Choices"
301="Moved Permanently"
302="Found"
303="See Other"
304="Not Modified"
305="Use Proxy"
306="(Unused)"
307="Temporary Redirect"
[Client Error 4xx]
400="Bad Request"
401="Unauthorized"
402="Payment Required"
403="Forbidden"
404="Not Found"
405="Method Not Allowed"
406="Not Acceptable"
407="Proxy Authentication Required"
408="Request Timeout"
409="Conflict"
410="Gone"
411="Length Required"
412="Precondition Failed"
413="Request Entity Too Large"
414="Request-URI Too Long"
415="Unsupported Media Type"
416="Requested Range Not Satisfiable"
417="Expectation Failed"
[Server Error 5xx]
500="Internal Server Error"
501="Not Implemented"
502="Bad Gateway"
503="Service Unavailable"
504="Gateway Timeout"
505="HTTP Version Not Supported"
转载地址:http://php.net/manual/zh/function.curl-getinfo.php