Create Post Request Using PHP GuzzleHTTP Using Custom header and Raw Body Data


Here is how to create POST request with custom headers and Raw body Using GuzzleHTTP:

$headers = ['Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/json'];

$data = json_encode([
'name' => 'yoesoff'
]);

$options = [
'body' => $data,
'headers' => $headers,
];

$result = $client->post($target_url, $options);

var_dump($result->getStatusCode());
dd($result->getBody());

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s