-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.php
44 lines (36 loc) · 1.59 KB
/
post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
// Go to the "tests" directory and start PHP as a WEB server:
//
// php -S localhost:8000 -t public
//
// Then you can run this script.
require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'utils.php';
use dbeurive\Http\Requester;
use dbeurive\Http\Code;
define('HOST', 'localhost');
define('PORT', 8000);
print "# Sending a POST request\n\n";
$requester = new Requester();
$query_string = '/handle_post.php';
$url = sprintf('http://%s:%d%s', HOST, PORT, $query_string);
$content = 'var=value';
$options = array(CURLOPT_USERPWD => 'admin:admin');
$report = null;
try {
$report = $requester->doPost($url, $content, 'text/html', $options);
} catch (\Exception $e) {
printf("%s\n", $e->getMessage());
exit(1);
}
printf("Request header:\n\n%s\n\n", format_code($report->getRequest()->getHeader()->getAsString()));
printf("Request content:\n\n%s\n\n", format_code($report->getRequest()->getContent()));
printf("Response header:\n\n%s\n\n", format_code($report->getResponse()->getHeader()->getAsString()));
$body = $report->getResponse()->getBody();
if (! is_null($body)) {
printf("Response body:\n\n%s\n\n", format_code($body));
}
printf("Response HTTP code: %s (%s)\n", $report->getResponse()->getCode(), Code::getDescription($report->getResponse()->getCode()));
printf("Response content type: %s\n", $report->getResponse()->getContentType());
printf("Response content length: %s\n", $report->getResponse()->getContentLength());
print "\n";