I need to send a post request to an api endpoint. While I try with Guzzle I get an error that says the method not allowed
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...)
But when I try with Ajax it works fine.
Here is the Guzzle code:
$headers = [
'Content-Type' => 'application/json',
];
$client = new Client(['headers' => $headers]);
$response = $client->post('https://api.***.com/v2/' , [
'json' => ["queries" => "Online MBA" ]
]);
Here is the call from Ajax
$.ajax({
url : 'https://***/runs?***',
method : 'POST',
contentType: 'application/json',
dataType: 'json',
data : JSON.stringify ({
"queries" : "Online MBA"
}),
success:function(result) {
console.log(result);
}
});
Is the problem in the following code?
'json' => ["queries" => "Online MBA" ]
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire