我需要向api端点发送发布请求。当我尝试使用Guzzle时,出现错误,提示该方法不允许
Client error: `POST https://api.***.com/v2/ ` resulted in a `405 Method Not Allowed` response: { "error": { "type": "method-not-allowed", "message": "This API end-point can only be accessed using the follo (truncated...)
但是当我尝试使用Ajax时,它可以正常工作。
这是枪口的代码:
$headers = [
'Content-Type' => 'application/json',
];
$client = new Client(['headers' => $headers]);
$response = $client->post('https://api.***.com/v2/' , [
'json' => ["queries" => "Online MBA" ]
]);
这是来自Ajax的电话
$.ajax({
url : 'https://***/runs?***',
method : 'POST',
contentType: 'application/json',
dataType: 'json',
data : JSON.stringify ({
"queries" : "Online MBA"
}),
success:function(result) {
console.log(result);
}
});
以下代码是否有问题?
'json' => ["queries" => "Online MBA" ]