0

I'm trying to call 3rd party API with POST method using curl. But I'm not getting response instead I got this random character when I dump the response

enter image description here

$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. Any help would be appreciated, thank you

5
  • I don't know what you expect us to do with this. You're setting up a cURL call to an API that you've removed. There's no way to know what you should be sending, or what you might expect in return. Commented Apr 4, 2021 at 4:55
  • Accept-Encoding:gzip,deflate,br can you explain what do you expect in reponse? Json or zip content? Commented Apr 4, 2021 at 4:58
  • @nice_dev hi, i'm expecting json as response Commented Apr 4, 2021 at 5:11
  • 2
    @Michael Could you remove that header and replace it with Accept-type:application/json and check? Commented Apr 4, 2021 at 5:12
  • As noted elsewhere, either remove the Accept-Encoding header, or try the solutions from stackoverflow.com/questions/310650/… Commented Apr 4, 2021 at 9:42

1 Answer 1

1

try to remove this $headers[]='Accept-Encoding:gzip,deflate,br';

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.