以下代码将检索在 php 中使用 CURL 而不是 https 检索到的 url 的正文内容。谁能告诉我如何编辑代码,因为我需要获取返回的数据而不仅仅是标题。
我这里做的测试是结果。你可以看到它有一个内容长度,我只是不知道如何访问它。
谢谢 斯蒂芬
错误:0
string(1457) "HTTP/1.1 200 OK 日期:2009 年 8 月 1 日星期六 06:32:11 GMT 服务器:Apache/1.3.41 (Darwin) PHP/5.2.4 mod_ssl/2.8.31 OpenSSL/0.9。 7l 缓存控制:max-age=60 过期时间:2009 年 8 月 1 日星期六 06:33:11 GMT 最后修改时间:2006 年 11 月 23 日星期四 17:44:53 GMT ETag:“97d620-44b-4565de15”接受范围: bytes Content-Length: 1099 Connection: close Content-Type: text/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);
?>
最佳答案
解决方法如下: 试试这个,只需保持其余编码与上面相同......
$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 使其仅返回页面内容。
关于php - 如何使用 CURL 获取 HTTPS 的 Body 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1215980/