Guzzle HTTP POST request in laravel

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Guzzle HTTP POST request in laravel



how to pass path parameter in guzzle HTTP Post request. I am having url like this - http://base_url/v1/rack/{id}/books



in my url {id} is the path parameter.


$addLibraryUrl = $base_url."v1/rack/{id}/book";
$headers["id"] = $id;
$requestContent['json'] = $data;
$client = new Client();
$response = $client->post($addLibraryUrl, [
"headers" => $headers,
"json" => json_encode($data)
]);




1 Answer
1



If you sent form params then you need to sent them as post params like :


// Initialize Guzzle client
$client = new GuzzleHttpClient(['headers'=> 'Some headers');

// Create a POST request
$response = $client->request(
'POST',
'http://yoururl.com',
[
'form_params' => [
'key1' => 'value1',
'key2' => 'value2'
]
]
);



Or like in your case change 'json' to form_params:


form_params


$addLibraryUrl = $base_url."v1/rack/{id}/book";
$headers["id"] = $id;
$requestContent['json'] = $data;
$client = new Client();
$response = $client->post($addLibraryUrl, [
"headers" => $headers,
"form_params" => json_encode($data)
]);






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to scale/resize CVPixelBufferRef in objective C, iOS

Keycloak server returning user_not_found error when user is already imported with LDAP

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”