-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.php
More file actions
71 lines (58 loc) · 1.72 KB
/
debug.php
File metadata and controls
71 lines (58 loc) · 1.72 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
// Start webserver: php -S localhost:2400 -t public
// Set credentials:
$username = "rest";
$password = "test";
// Which method do you want to test?
// GET, POST, PUT or DELETE
$requestMethod = 'PATCH';
// URL:
$url = 'http://localhost:2400/v1/Users';
switch ($requestMethod) {
case "GET":
$ch = curl_init($url);
break;
case "POST":
$body = [
"name" => "Greta Garbo",
"age" => "93",
"city" => "Los Angeles",
"country" => "California"
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body));
break;
case "PUT":
$body = [
"name" => "John T. Piloso",
"age" => "29",
"city" => "Flagstaff",
"country" => "Arizona"
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body));
break;
case "DELETE":
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
break;
case "PATCH":
$url = 'http://localhost:2400/v1/Calculator/multiply';
$body = [
"a" => 12,
"b" => 2.5
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body));
break;
}
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HEADER, true);
if (!$output = curl_exec($ch)) {
trigger_error(curl_error($ch));
}
curl_close($ch);