php-ccurl检查ssl连接



想要一些关于我的php curl连接的帮助-在我的firebug控制台中,我一直收到这个错误

注意:未定义的索引:C:\examplep\htdocs\labs\test2\get.php中的主机6行
错误:3格式错误的

AJAX代码:

var hostName = $("input#host").val();
dataString = hostName;
$.ajax({
type: "GET",
url: "get.php",
data: dataString,
dataType: "json",

PHP CURL代码:

<?php
if($fp = tmpfile())
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $_GET['host']);
curl_setopt($ch, CURLOPT_STDERR, $fp);
curl_setopt($ch, CURLOPT_CERTINFO, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
$result = curl_exec($ch);
curl_errno($ch)==0 or die("Error:".curl_errno($ch)." ".curl_error($ch));
fseek($fp, 0);//rewind
$str='';
while(strlen($str.=fread($fp,8192))==8192);
echo $str;
fclose($fp);
}
?>

--反应--

HTTP/1.1302找到缓存控制:私有内容类型:text/html;charset=UTF-8位置:http://www.google.com.au/?gfe_rd=cr&ei=VbwrVa_RFsPu8wfN54HYBQ内容长度:262日期:2015年4月13日星期一12:53:41 GMT服务器:GFE/2.0备用协议:80:quic,p=0.5*重建URL到:www.google.com/*在DNS缓存中找不到主机名*正在尝试216.58.220.100…*连接到www.google.com(216.58.220.1 00)端口80(#0)>HEAD/HTTP/1.1主机:www.google.com接受:/<HTTP/1.1 302找到<缓存控制:private<内容类型:text/html;charset=UTF-8<地点:http://www.google.com.au/?gfe_rd=cr&ei=VbwrVa_RFsPu8wfN54HYBQ<内容长度:262<日期:2015年4月13日星期一12:53:41 GMT<服务器:GFE/2.0<替代方案:80:quic,p=0.5<*连接#0到主机www.google.com的完好无损

http_build_query不会创建有效的url,只会为GET请求格式化参数数组。你应该做一些类似的事情:

$url = "https://".$_REQUEST['host']."?"."{$query_string}";

在您的示例中,生成的url将是

https://www.google.com?host=www.google.com

注意"https">

您的数据字符串是错误的

dataString = hostName;

这将只包含数据

dataString = {"host":hostName};

它应该在GET字符串中传递参数host

最新更新