我正在向post
机构发出json
请求。首先,尝试使用MacOS终端,它工作。
curl -H "Content-Type: application/json" -H "Accept:application/json" -H "apiKey:API_KEY" -X POST -k -d '{some_json_data}' https://portal.betterplace.co.in/VishwasAPI/api/public/v2/aadhaar/authenticate
当我使用PHP cURL尝试以下时,同样的请求失败
$body = [SOME_KEY_VALUE_PAIR];
$str = json_encode($body);
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_URL,'https://portal.betterplace.co.in/VishwasAPI/api/public/v2/aadhaar/authenticate');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'apiKey' => 'API_KEY',
'Content-Type' => 'application/json',
'Accept' => 'application/json']
);
$res = curl_exec($ch);
echo $res;
curl_close($ch);
有了这个,我收到了以下回复:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /VishwasAPI/api/public/v2/aadhaar/authenticate on this server.</p>
</body></html>
谁能告诉我为什么会发生这种情况?
答案 0 :(得分:0)
我知道这很旧了,但是今天我遇到了同样的问题,找到了此页面(当我没有看到回复时感到失望),但是后来我在那找到了解决方法:cURL + Laravel Valet + dnsmasq not working
希望您在最近两年内找到了解决方案;)