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
$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
Advertisement
Answer
try to remove this $headers[]='Accept-Encoding:gzip,deflate,br';