我做了一些卷曲过程,一些网站必须设置CURLOPT_HEADER, true
,这样才能得到html代码.
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $url);
curl_setopt($ch2, CURLOPT_HEADER, true);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec($ch2);
curl_close($ch2);
echo $html;
Run Code Online (Sandbox Code Playgroud)
返回数据如:
HTTP/1.0 200 OK Date: Wed, 14 Nov 2012 17:58:26 GMT Expires: Wed, 14 Nov 2012 18:08:26 GMT Cache-Control: max-age=600...
<html...
Run Code Online (Sandbox Code Playgroud)
那么如何删除之前的数据<html>
(CURLOPT_HEADER返回数据:HTTP/1.0 200 OK ...)?
CURLOPT_HEADER
不会影响网站返回给您的内容.你可以删除它,如果你得到空的内容 - 那么别的东西是错的.
CURLOPT_HEADER
只是为了您的方便,所以你可以看到服务器回复你的脚本.某些Web API在标头中传递数据,这使您可以访问它.
您可以像这样从标题中拆分内容
list($header, $body) = explode("\r\n\r\n", $content, 2); // Notice the "2" limit!
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7020 次 |
最近记录: |