下面的代码将检索在php中使用CURL而不是https检索到的url的正文内容。谁能告诉我,我如何编辑代码,因为我需要得到返回的数据,而不仅仅是头。
这是我在这里做的测试的结果。你可以看到它有一个内容长度,我只是不知道如何访问它。
谢谢,斯蒂芬
错误:0
字符串(1457) "HTTP/1.1 200 OK Date: Sat,01 Aug 2009 06:32:11 GMT服务器: Apache/1.3.41 (达尔文) PHP/5.2.4 mod_ssl/2.8.31 OpenSSL/0.9.7l缓存控制: max-age=60 Expires: Sat,01 Aug 2009 06:33:11 GMT上次修改时间:清华,2006年11月23日17:44:53 GMT ETag:"97d620-44b-4565de15“接受范围:字节内容长度: 1099连接:关闭内容类型:文本/html”
<?php
$curl_handle=curl_init();
$username = "";
$password = "";
$fullurl = "http://www.queensberry.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_URL, $fullurl);
$returned = curl_exec($ch);
curl_close ($ch);
var_dump($returned);
?>
发布于 2010-01-14 16:41:34
以下是解决方案:试试这个,只需保持代码的其余部分与上面相同……
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
// curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_URL, $fullurl);
$returned = curl_exec($ch);
curl_close ($ch);
var_dump($returned);
如果将CURLOPT_HEADER更改为0,则只返回页面内容。
发布于 2009-08-01 13:41:50
$fullurl
不应该是"https://www.queensberry.com“吗?
当我如上所述更改$fullurl
并运行代码时,var_dump
显示了“正在构建”页面。
发布于 2014-05-14 22:02:02
如果您仍然需要标题,这意味着不能将CURLOPT_HEADER设置为0,您可以通过查找空行(两个CRLF)来查找正文的开头。请参阅规范:http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html
所以这应该能做好这项工作:
$data = curl_exec($ch);
$start = strpos($data, "\r\n\r\n") + 4;
$body = substr($data, $start, strlen($data) - $start);
https://stackoverflow.com/questions/1215980
复制相似问题