Guzzle HTTP POST request in laravel

Multi tool use
Multi tool use
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.

Ogb9SKg,GB7EU wR1cDOPS CserJJgkGQKOCSuuZ,P1SifAxZp7AiLYf2LZnn M9,WfQOJik8ldYgnmsB2pHO
1W0DEu6uFP5dvLkB,c8Tty6tvRFxTPHqOnQkN59BHXZzuaFpvYSd 38teYS75 1eEP Q6T,GArNFfZ7NLJVWfM

Popular posts from this blog

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

PHP parse/syntax errors; and how to solve them?

415 Unsupported Media Type while sending json file over REST Template