Last active
April 23, 2016 13:21
-
-
Save MacDada/cbb9c2ec930cf88ac8cf1463c5f9d415 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
$client = new GuzzleHttp\Client(); | |
$response = $client->request('POST', 'http://localhost:8000/hello/world', [ | |
'form_params' => [ | |
'name' => 'Norbert', | |
], | |
'timeout' => 30, | |
]); | |
echo $response->getBody(); |
This file contains hidden or 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 | |
$socket = fsockopen("localhost", 8000, $errno, $errstr, 30); | |
if (!$socket) { | |
echo "$errstr ($errno)<br />\n"; | |
} else { | |
$post_data = "name=Norbert"; | |
$http = "POST /hello/world HTTP/1.1\r\n"; | |
$http .= "Host: localhost\r\n"; | |
$http .= "User-Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n"; | |
$http .= "Content-Type: application/x-www-form-urlencoded\r\n"; | |
$http .= "Content-length: " . strlen($post_data) . "\r\n"; | |
$http .= "Connection: close\r\n\r\n"; | |
$http .= $post_data . "\r\n\r\n"; | |
fwrite($socket, $http); | |
$contents=""; | |
while (!feof($socket)) { | |
$contents .= fgets($socket, 4096); | |
} | |
} | |
fclose($socket); | |
echo $contents; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment