卷曲HTTPS无法解决

时间:2015-09-24 06:32:40

标签: php curl https

   concat:{
      options: {
        separator: ';'
      },
      dist:{
        src:['src/**/*.js', '!src/**/test*.js'],
        dest: 'dist/<%= pkg.name %>.js'
      }
    }

我试图对https网站做一个卷曲,它说dns无法解决。但该网站我可以通过浏览器访问它

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $curl_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__)."/cacert.pem");
// Edit: prior variable $postFields should be $postfields;
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($ch);

if(curl_errno($ch))
{
    echo 'error:' . curl_error($ch);
}

print_r($result);
$array_json = json_decode($result, true);

1 个答案:

答案 0 :(得分:0)

我在我自己的本地分期付款

$ch = curl_init();

$curl_url = 'https://example.com';
curl_setopt($ch, CURLOPT_URL, $curl_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__)."/cacert.pem");
// Edit: prior variable $postFields should be $postfields;
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($ch);

if(curl_errno($ch))
{
  echo 'error:' . curl_error($ch);
}

print_r($result);

它正常工作并打印结果。我想你的问题在于这个字符串

curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__)."/cacert.pem");

您可能会错误路径或加载错误的证书。我在我的例子中评论了这一行。