【发布时间】:2021-06-30 09:51:28
【问题描述】:
我正在尝试使用 curl 使用 POST 方法调用第 3 方 API。但是我没有得到响应,而是在我转储响应时得到了这个随机字符
$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();
我尝试使用 chrome 网络选项卡进行调试,但我的 API 调用未显示在我的网络选项卡中。任何帮助将不胜感激,谢谢
【问题讨论】:
-
我不知道您希望我们对此做什么。您正在为已删除的 API 设置 cURL 调用。没有办法知道您应该发送什么,或者您可能期望得到什么回报。
-
Accept-Encoding:gzip,deflate,br你能解释一下你对回应的期望吗? Json 还是 zip 内容? -
@nice_dev 嗨,我期待 json 作为响应
-
@Michael 你能删除那个标题并用
Accept-type:application/json替换它并检查吗? -
@nice_dev 成功了!谢谢