I need to send HTML components in the BODY of a POST throught Guzzle.
These are the HTML TAGS:
$strData = "<p style='background:url(/clear.png?org_id=1snn5n9w&session_id=123456789&m=1)'>< / p >
<img src='/clear.png?org_id=1snn5n9w&session_id=123456789&m=2' alt=''>";
My Guzzle code is:
$client = new GuzzleHttp\Client(['base_uri' => 'https://thirdURL.com/Test.htm', 'http_errors'=>true]);
$resH = $client->post('https://thirdURL . com/Test.htm',[
'form_params' =>['body' => $strData]]);
Is this the correct way to send this kind of objects via Guzzle? Thanks for your help.
Regards.
If you are not trying to send data as a query parameter (think of a form submission) then there is no need to use "form_params".
If all you want is the body to contain the desired html string you should be able to do the following:
$resH = $client->post('https://thirdURL.com/Test.htm',[
'body' => $strData,
]);
More information can be obtained by reading through the Guzzle Documentation on Post Requests
The 'form_params' request option is essentially a short-cut way of performing:
$response = $client->post($uri, [
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
],
'body' => http_build_query($form_params_array),
])
So in essence, for your particular use case the body of your http request would contain the post query and the html content.
The answer to your question of 'will it work?', is simply (and albeit unhelpful) -- "I don't know". At the end of the day, it all depends on what the server will accept.