I am trying to work out why a Guzzle PUT request, in a Laravel 5 application, I am making is returning a 400 error when the same request works fine in SoapUI. I am trying to send a JSON string to an API with a PUT.
I am having no trouble getting data from this API it is putting the JSON body I am having trouble with.
The $base_api variable is the base url of the API server.
The $uri = 'refData/dropRoutes/'; and this is the particular endpoint I am trying to post the JSON body to.
Here is my code for setting up the Client
$client = new Client([
'base_uri' => $base_api,
'timeout' => 10.0,
'proxy' => ['no' => ['.casino.internal']],
'verify' => false,
'headers' => [
'Accept' => 'application/json',
'Accept-Encoding' => 'gzip,deflate',
'tseg-user' => $_COOKIE['egmtool_name'],
'tseg-source' => 'Drop Collection Tool',
'tseg-host' => request()->ip(),
'tseg-context' => '',
'tseg-datetime' => Date('d-m-Y H:i:s' ),
'tseg-property' => $location
],
]);
Here is the request I am trying
$response = $client->request(
'PUT',
$uri,
['debug' => fopen('C:\\xampp\\htdocs\\egmbank\\storage\\logs\\log2.txt','a+')],
['auth' => [config('app.api_username'), config('app.api_password')]],
['json' => $json_body]
);
I have copied the JSON string, from SoapUI to ensure I am testing with the same data.
Because the PUT is working with SoapUI the issue seems to be how I am trying to PUT the data.
I would appreciate it if someone could point me in the right direction with my Client configuration and the way I am trying to PUT the JSON body.
I have tried changing the 'json' => $json_body to 'body => $json_body and then setting the 'Content-type' to 'application/json' in the header but this made no difference to the result I am getting
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire