-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
63 lines (47 loc) · 1.54 KB
/
index.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
$headers = apache_request_headers();
$headers_native = array();
$body = file_get_contents('php://input');
// change this to your server name and port
$scheme = "http";
$server_name = "localhost";
$server_port = 1323;
// don't change anything below this line
$method = $_SERVER['REQUEST_METHOD'];
$request_uri = $_SERVER['REQUEST_URI'];
$url = $scheme."://".$server_name.$request_uri;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, $server_port);
$headers['Host'] = $server_name;
$headers['Content-Length'] = strlen($body);
foreach($headers as $key=>$value) {
$headers_native[] = $key.":"." ".$value;
}
if ($method == 'GET') {
curl_setopt($ch, CURLOPT_POST, false);
} else if ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
} else if ($method == 'PUT') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
} else if ($method == 'DELETE') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
}
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_native);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_TIMEOUT , 60);
$result = curl_exec($ch);
curl_close($ch);
$response = explode("\r\n\r\n", $result, 2);
$header_lines = explode("\r\n", $response[0]);
foreach($header_lines as $line) {
header($line);
}
if(isset($response[1])) {
echo $response[1];
}