Can PHP cURL retrieve response headers AND body in a single request?

后端 未结 13 1734
粉色の甜心
粉色の甜心 2020-11-22 03:28

Is there any way to get both headers and body for a cURL request using PHP? I found that this option:

curl_setopt($ch, CURLOPT_HEADER, true);
相关标签:
13条回答
  • 2020-11-22 03:59

    My way is

    $response = curl_exec($ch);
    $x = explode("\r\n\r\n", $v, 3);
    $header=http_parse_headers($x[0]);
    if ($header=['Response Code']==100){ //use the other "header"
        $header=http_parse_headers($x[1]);
        $body=$x[2];
    }else{
        $body=$x[1];
    }
    

    If needed apply a for loop and remove the explode limit.

    0 讨论(0)
提交回复
热议问题