我的cURL代码的任何错误(http状态0)? [英] Anything wrong with my cURL code (http status of 0)?
本文介绍了我的cURL代码的任何错误(http状态0)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我复制并粘贴发送到我的浏览器的url,我会一直得到0的状态,我立即得到一个json对象。
Consistently getting a status of 0 even though if I copy and paste the url sent into my browser, I get a json object right back
<?php
$mainUrl = "https://api.xxxx.com/?";
$co = "xxxxx";
$pa = "xxxx";
$par = "xxxx";
$part= "xxxx";
$partn = "xxxx";
$us= "xxx";
$fields_string;
$fields = array(
'co'=>urlencode($co),
'pa'=>urlencode($pa),
'par'=>urlencode($par),
'part'=>urlencode($part),
'partn'=>urlencode($partn),
'us'=>urlencode($us)
);
foreach($fields as $key=>$value) { $fields_string .= $key . '=' . $value . '&' ;}
$fields_string = rtrim($fields_string, "&");
$fields_string = "?" . $fields_string;
$url = "https://api.xxxxx.com/" . $fields_string;
$request = $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,'3');
$content = trim(curl_exec($ch));
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
print $url;
print $http_status;
print $content;
?>
推荐答案
意识到我遇到了SSL问题。只需将CURLOPT_SSL_VERIFYPEER和CURLOPT_SSL_VERIFYHOST设置为false即可。工程。
Realized that I was having SSL issues. Simply set CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST to false. Works.
这篇关于我的cURL代码的任何错误(http状态0)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文