如何使用CURL获取HTTPS的Body内容 [英] How to Get Body content of HTTPS using CURL

查看:2539
本文介绍了如何使用CURL获取HTTPS的Body内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码将检索使用PHP中(而不是https)使用CURL检索的网址的正文内容。任何人都可以告诉我如何编辑代码,因为我需要获取返回的数据不只是标题。

The following code will retrieve the body content of a url retrieved using CURL in php but not https. Can anyone tell me how I edit the code as I need to get the data returned not just the header.

从测试我在这里是结果。你可以看到它有一个内容长度,我只是不知道如何访问它。

From the test I did here is the result. You can see it has a content-length, I just don't know how to access it.

感谢
Stephen

Thanks Stephen

错误:0

string(1457)HTTP / 1.1 200 OK日期:Sat,01 Aug 2009 06:32:11 GMT服务器:Apache / 1.3.41(Darwin)PHP / 5.2.4 mod_ssl / 2.8.31 OpenSSL / 0.9 .7l Cache-Control:max-age = 60 Expires:Sat,2009年8月1日06:33:11 GMT上次修改时间:Thu,23 Nov 2006 17:44:53 GMT ETag:97d620-44b-4565de15范围:bytes Content-Length:1099 Connection:close Content-Type:text / html

string(1457) "HTTP/1.1 200 OK Date: Sat, 01 Aug 2009 06:32:11 GMT Server: Apache/1.3.41 (Darwin) PHP/5.2.4 mod_ssl/2.8.31 OpenSSL/0.9.7l Cache-Control: max-age=60 Expires: Sat, 01 Aug 2009 06:33:11 GMT Last-Modified: Thu, 23 Nov 2006 17:44:53 GMT ETag: "97d620-44b-4565de15" Accept-Ranges: 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);


?>


推荐答案

这里是解决方案:
,只要保持其余的编码与上面一样...

Here is the solution: Try this, just keep rest of the coding same as above...

$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,只返回页面内容。

Changing CURLOPT_HEADER to 0 makes it so that only the page content is returned.

这篇关于如何使用CURL获取HTTPS的Body内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆