Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

melx's avatar
Level 4

http client Post Body Raw In controller

I want to how can run my API below with Body Raw and get response output

API:

   http://icloud.scontrols.com:8000/OpenApi/LDC

Body raw

                {FAction:"QueryLBSMonitorListByFGUIDs",FTokenID:"8ee50e2f-3987-43f1-90f9- 
               7b3a37bc6345",FGUIDs:"49113c96-e808-41b3-278cb-811820992f49",FType:"17"}
0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

You can use the Guzzle HTTP client to make a POST request to the API with the given raw body. Here's an example code snippet that you can use in your controller:

use GuzzleHttp\Client;

$client = new Client();

$response = $client->post('http://icloud.scontrols.com:8000/OpenApi/LDC', [
    'headers' => [
        'Content-Type' => 'application/json',
    ],
    'body' => '{FAction:"QueryLBSMonitorListByFGUIDs",FTokenID:"8ee50e2f-3987-43f1-90f9-7b3a37bc6345",FGUIDs:"49113c96-e808-41b3-278cb-811820992f49",FType:"17"}',
]);

$output = $response->getBody()->getContents();

// Do something with the output

In this example, we're creating a new instance of the Guzzle HTTP client and making a POST request to the API with the given URL. We're also setting the Content-Type header to application/json and passing the raw body as a string in the body option.

After making the request, we're getting the response body contents and storing it in the $output variable. You can then do something with the output as needed.

Please or to participate in this conversation.