Last active
May 1, 2023 19:52
-
-
Save juampynr/bfd5e8e38424618b3065b3f6a9713e69 to your computer and use it in GitHub Desktop.
Sample POST request with Guzzle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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)); |
Set the header as "content-type" : "application/x-www-form-urlencoded" to accept form_params.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What do do when you post other content?
e.g. "application/json"?
So neither a MIME-Multipart nor applicaton/form-data?