我正在尝试使用curl方法进行API调用。
我使用来自我想要集成的应用程序的创建者的演示项目,在MAMP上尝试了相同的调用,所有这些都是PHP代码...现在,在服务器上,我刚刚包含了PHP库,并试图用PHP拨打电话,但我不知道为什么得到状态码0。
npm i -D ts-node
}
我不知道该怎么办..因为状态仅为0 ..诸如403、404等之类的东西。
谢谢您的帮助。
编辑
private function _cURL($url, $data, $request, $headAccept) {
$headers = array($headAccept, "Authorization: Basic " . $this->hash);
$ch = curl_init($url);
// curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
if ( !empty($data) ) {
$headers[] = "Content-Type: application/json; charset=utf-8";
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
}
if ( !empty($request)) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// debugging
$isDebug = self::DEBUG_ON_ERROR;
if ( !empty($isDebug) ) {
$debug = array(
'URL: ' => $url,
'data: ' => $data,
'headers: ' => $headAccept,
);
echo '<pre>' , print_r($debug, true), '</pre>';
}
return $ch;
编辑2
调用 $ch = $this->_cURL($url, $data, $request, $headAccept);
$return = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
后,响应为:
print_r(curl_getinfo($ch));
编辑3
我从生产环境下载了该项目,并使用(
[url] => https://ws.smartbill.ro:8183/SBORO/api/estimate
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.007306
[namelookup_time] => 0.007255
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0
[redirect_time] => 0
[redirect_url] =>
[primary_ip] =>
[certinfo] => Array
(
)
[primary_port] => 0
[local_ip] =>
[local_port] => 0
)
在本地主机上进行了测试,并且可以正常工作...服务器问题。.但是我不知道该怎么办...
答案 0 :(得分:0)
尝试使用此功能
public static function get($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1000);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
// dd($info);
curl_close($ch);
$result = json_decode($result, true);
return $result;
}
在我的laravel项目中效果很好。
看看是否有帮助!