简体   繁体   English

curl php 没有得到响应

[英]curl php not getting response

I'm trying to call 3rd party API with POST method using curl.我正在尝试使用 curl 使用 POST 方法调用第 3 方 API。 But I'm not getting response instead I got this random character when I dump the response但是我没有得到响应,而是在我转储响应时得到了这个随机字符

在此处输入图像描述

$data=array(
    "referenceId"=>$orders->reference,
    "currency"=>"IDR","amount"=>intval($total_bayar),
    "callbackUrl"=>"https://www.some.url",
    "paymentResultUrl"=>"https://www.some.url",
    "paymentCancelUrl"=>"https://www.some.url",
    "merchantReferenceId"=>$orders->reference,
    "customerInfo"=>array(
        "mobileNumber"=>$customerAddress->phone,
        "fullName"=>$customerAddress->firstname.''.$customerAddress->lastname
    ),
    "shippingAddress"=>array(
        "countryCode"=>"ID",
        "lines"=>[$customerAddress->address1],
        "postCode"=>$customerAddress->postcode
    ),
    "billingAddress"=>array(
        "countryCode"=>"ID",
        "lines"=>[$customerAddress->address1],
        "postCode"=>$customerAddress->postcode
    ),
    "taxAmount"=>0,
    "items"=>$itemsDetail
);

$postdata=json_encode($data);
$headers=array();
$headers[]='Content-type:application/json';
$headers[]='Connection:keep-alive';
$headers[]='Accept-Encoding:gzip,deflate,br';
$headers[]='Authorization:Basic'.base64_encode('some_key:some_pass');

$service_url='https://www.some.url';
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$service_url);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,0);
curl_setopt($ch,CURLOPT_TIMEOUT,400);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_HTTPAUTH,CURLAUTH_ANY);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postdata);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
$curl_response=curl_exec($ch);
$httpCode=curl_getinfo($ch,CURLINFO_HTTP_CODE);

if($curl_response===false)
    $curl_response=curl_error($ch);

curl_close($ch);

print_r($curl_response);
die();

I tried to debug using the chrome network tab, but my API call doesn't show up in my network tab.我尝试使用 chrome 网络选项卡进行调试,但我的 API 调用未显示在我的网络选项卡中。 Any help would be appreciated, thank you任何帮助将不胜感激,谢谢

try to remove this $headers[]='Accept-Encoding:gzip,deflate,br';尝试删除此$headers[]='Accept-Encoding:gzip,deflate,br';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM