PHP Curl不适用于HTTPS页面

时间:2015-08-08 15:16:38

标签: php curl php-curl

我尝试使用PHP Curl提交使用post方法的值。但它不适用于HTTPS页面。任何机构审查我的下面的代码,并检查我做错了什么。

$url = 'https://www.whoisxmlapi.com/user/create.php';
$fields = array(
                        'username' => urlencode("check123"),
                        'email' => urlencode("check123@gmail.com"),
                        'password' => urlencode("password"),
                        'password_confirmation' => urlencode("password"),
                        'firstname' => urlencode("firstname"),
                        'lastname' => urlencode("lastname"),
                        'organization' => urlencode("organization"),
                        'captcha' => urlencode("captcha")
                );

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');


//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,3);
curl_setopt($ch,CURLOPT_TIMEOUT, 20);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

2 个答案:

答案 0 :(得分:2)

请首先在代码中添加一些有用的错误检查

//execute post
$result = curl_exec($ch);

if( $result === false) {
    echo 'Curl error: ' . curl_error($ch);
}

然后你可能会解决自己的问题

答案 1 :(得分:0)

分享你得到的错误, 或使用此卷曲选项​​进行测试

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

0:不检查公用名(CN)属性

1:检查公共名称属性是否至少存在

2:检查公用名是否存在,以及它是否与服务器的主机名匹配