libcurl 調用curl_easy_getinfo( ) 返回錯誤碼對照


//執行設置好的操作   
    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"

 

轉載地址:http://php.net/manual/zh/function.curl-getinfo.php


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM