php curl 检查 ssl 连接

标签 php jquery ssl curl

我的 php curl 连接需要一些帮助 - 在我的 firebug 控制台中,我不断收到此错误

Notice: Undefined index: host in C:\xampp\htdocs\labs\test2\get.php on line 6
Error:3 malformed

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 Location: 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 * Rebuilt URL to: www.google.com/ * Hostname was NOT found in DNS cache * Trying 216.58.220.100... * Connected to www.google.com (216.58.220.100) port 80 (#0) > HEAD / HTTP/1.1 Host: www.google.com Accept: / < HTTP/1.1 302 Found < Cache-Control: private < Content-Type: text/html; charset=UTF-8 < Location: 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

最佳答案

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

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

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

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

注意“https”

关于php curl 检查 ssl 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29605043/

上一篇:aws的ssl证书

下一篇:通过 HTTPS 的 WCF REST

相关文章:

java - 如何从 Nexus OSS 连接到 HTTPS 存储库?

authentication - 为什么在设置新的 jks 后尝试发布 API 时 WSO2 API Manager 会抛出错误

php - 如果参数不是整数,如何以不同方式定义路由

php - Goutte - 获取日期在顶部、标题在下面的列表

java - 如何为 servlet 和对象数组设置数据表?

jquery - 如何在slideToggle上添加/删除类?

javascript - data-src 属性中的图像是否在页面加载时下载?

php - 为什么我的多维数组没有正确初始化和/或返回?

php - 我们需要从 mysql 检索所有行。并且表只有一列,例如名称。哪种方法更好?

java - 在 SSL 握手中,如果服务器发送带有空 'Cert Authorities' 列表的 CertificateRequest,我们能否让客户端发送证书