【发布时间】:2021-02-05 09:16:43
【问题描述】:
我试图向这个 API 发送一个发布请求,它返回给我
"error": "unauthorized", "error_description": "An Authentication object was not found in the SecurityContext" 当我用邮递员发送相同的请求时,它工作正常。
这是我正在使用的代码
$url = config('payhere.cancel_url');
$postRequest = array(
'subscription_id'=>$payhereID
);
$headers = array(
'Authorization' =>'Bearer '.$accessToken,
'Content-Type'=>'application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// SSL important
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postRequest);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($ch);
curl_close($ch);
$respo = $this -> response['response'] = json_decode($output);
【问题讨论】: