PHP cURL 可以在單個請求中檢索響應標頭和正文嗎? - Can PHP cURL retrieve response headers AND body in a single request?

問題:

Is there any way to get both headers and body for a cURL request using PHP?有沒有辦法使用 PHP 獲取 cURL 請求的標頭和正文? I found that this option:我發現這個選項:

curl_setopt($ch, CURLOPT_HEADER, true);

is going to return the body plus headers , but then I need to parse it to get the body.將返回body 和 headers ,但隨後我需要解析它以獲取正文。 Is there any way to get both in a more usable (and secure) way?有沒有辦法以更可用(和安全)的方式獲得兩者?

Note that for "single request" I mean avoiding issuing a HEAD request prior of GET/POST.請注意,對於“單個請求”,我的意思是避免在 GET/POST 之前發出 HEAD 請求。


解決方案:

參考一: https://stackoom.com/question/cWxm
參考二: Can PHP cURL retrieve response headers AND body in a single request?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章