Skip to content

Instantly share code, notes, and snippets.

@MostafaEzzelden
Forked from juampynr/guzzle_post.php
Created December 25, 2018 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MostafaEzzelden/ff7ef3811cb6618764e754fa1eb1b06e to your computer and use it in GitHub Desktop.
Save MostafaEzzelden/ff7ef3811cb6618764e754fa1eb1b06e to your computer and use it in GitHub Desktop.
Sample POST request with Guzzle
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'http://example.com',
]);
$payload = file_get_contents('/my-data.xml');
$response = $client->post('the/endpoint', [
'debug' => TRUE,
'body' => $payload,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
]
]);
$body = $response->getBody();
print_r(json_decode((string) $body));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment