culr学习三: curl_easy_perform使用

转载地址:https://blog.csdn.net/weixin_30708329/article/details/95324280?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522158388890019724835830955%2522%252C%2522scm%2522%253A%252220140713.130056874..%2522%257D&request_id=158388890019724835830955&biz_id=0&utm_source=distribute.pc_search_result.none-task
//执行设置好的操作 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连接资源句柄的信息

说明

mixed curl_getinfo ( resource $ch [, int $opt = 0 ] )

获取最后一次传输的相关信息。

参数

 

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"

猜你喜欢

转载自www.cnblogs.com/cdy0626/p/12460396.html