想要一些帮助我的php curl连接 - 在我的firebug控制台中我一直收到这个错误
注意:未定义的索引:第6行的C:\ xampp \ htdocs \ labs \ test2 \ get.php中的主机错误: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.1 302 Found Cache-Control:private Content-Type:text / html; charset = UTF-8位置:http://www.google.com.au/?gfe_rd = cr&ei = VBwrVa_RFsPu8wfN54HYBQ内容长度:262日期:星期一,13四月2015 12:53:41 GMT服务器:GFE / 2.0替代 - 协议:80:quic,p = 0.5 *重建网址:www.google.com/ 在DNS缓存中找不到主机名尝试216.58.220.100 ... 已连接到www.google.com(216.58.220.100)端口80(#0)> HEAD / HTTP / 1.1主机:www.google.com接受:/ <HTTP / 1.1 302找到<Cache-Control:private <Content-Type:text / html; charset = UTF-8 <位置:http://www.google.com.au/?gfe_rd = cr&ei = VBwrVa_RFsPu8wfN54HYBQ <Content-Length:262 <Date:Mon,13 Apr 2015 12:53:41 GMT <Server:GFE /2.0 <Alternate-Protocol:80:quic,p = 0.5 < Connection#0 to host www.google.com left intact
2 回答
http_build_query不会创建有效的URL,而只会格式化GET请求的parameters数组 . 你应该做的事情如下:
在您的示例中,生成的URL将是
注意“https”
您的数据字符串错误
那只会包含数据
那应该在你的GET字符串中传递参数
host