How to remove HTTP headers from CURL response?

前端 未结 10 1143
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 17:26

I have a php script that returns just plain text without any html. Now I want to make a cURL request to that script and I get the following response:

<
相关标签:
10条回答
  • 2020-12-13 17:45

    If you are using nuSoap, you can access data without headers with $nsoap->responseData or $nsoap->response, if you want the full headers.

    Just in case someone needs that.

    0 讨论(0)
  • 2020-12-13 17:48

    If for some reason you have to curl_setopt($ch, CURLOPT_HEADER, 1); to get cookies for example, the following worked for me. Not sure if it's 100% reliable but worth a try

    $foo = preg_replace('/HTTP(.*)html/s',"",$curlresult);
    
    0 讨论(0)
  • 2020-12-13 17:48
    $content = null;
    
    $ch = curl_init();
    $rs = curl_exec($ch);
    
    if (CURLE_OK == curl_errno($ch)) {
      $content = substr($rs, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
    }
    
    curl_close($ch);
    
    echo $content;
    
    0 讨论(0)
  • 2020-12-13 17:50

    Just don't set CURLOPT_HEADER!

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