Skip to content

Instantly share code, notes, and snippets.

@mageekguy
Created February 16, 2015 09:23
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 mageekguy/d2c337d040b33e453563 to your computer and use it in GitHub Desktop.
Save mageekguy/d2c337d040b33e453563 to your computer and use it in GitHub Desktop.
Guzzle, allow_redirects and cookies are in a boat...
<?php
$httpClient = new \GuzzleHttp\Client;
$response = $httpClient->post('http://foo.bar', [ 'body' => [ 'username' => 'mageekguy', 'password' => 'A very strong password, isn\' it?', ], 'allow_redirects' => false, 'cookies' => true ]);
echo '<pre>';
var_dump($response->getStatusCode(), $response->getHeaders());
echo '</pre>';
/*
int(302)
array(5) {
["Date"]=>
array(1) {
[0]=>
string(29) "Mon, 16 Feb 2015 09:21:11 GMT"
}
["Server"]=>
array(1) {
[0]=>
string(6) "Apache"
}
["Location"]=>
array(1) {
[0]=>
string(15) "admin/index.php"
}
["Content-Length"]=>
array(1) {
[0]=>
string(1) "0"
}
["Content-Type"]=>
array(1) {
[0]=>
string(11) "'text/html'"
}
}
*/
$response = $httpClient->post('http://foo.bar', [ 'body' => [ 'username' => 'mageekguy', 'password' => 'A very strong password, isn\' it?', ], 'allow_redirects' => true, 'cookies' => true ]);
echo '<pre>';
var_dump($response->getStatusCode(), $response->getHeaders());
echo '</pre>';
/*
int(200)
array(6) {
["Date"]=>
array(1) {
[0]=>
string(29) "Mon, 16 Feb 2015 09:22:38 GMT"
}
["Server"]=>
array(1) {
[0]=>
string(6) "Apache"
}
["P3P"]=>
array(1) {
[0]=>
string(28) "CP="CUR ADM OUR NOR STA NID""
}
["Set-Cookie"]=>
array(1) {
[0]=>
string(74) "sessionID=phpads54e1b6de2d4bf6-59183461; path=/; domain=fh.v1.adaccess.dev"
}
["Transfer-Encoding"]=>
array(1) {
[0]=>
string(7) "chunked"
}
["Content-Type"]=>
array(1) {
[0]=>
string(29) "text/html; charset=ISO-8859-1"
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment