Skip to content

Instantly share code, notes, and snippets.

@MacDada
Last active April 23, 2016 13:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save MacDada/cbb9c2ec930cf88ac8cf1463c5f9d415 to your computer and use it in GitHub Desktop.
<?php
$client = new GuzzleHttp\Client();
$response = $client->request('POST', 'http://localhost:8000/hello/world', [
'form_params' => [
'name' => 'Norbert',
],
'timeout' => 30,
]);
echo $response->getBody();
<?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