-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
64 lines (53 loc) · 1.56 KB
/
test.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
64
<?php
//[url] [tip] [params] [json] [heads]
$handle = curl_init();
$url = $_POST['url'];
$postArray = [];
if ($_POST['params'] != '')
$postArray = unserializeArea($_POST['params']);
$headArray = explode("\n", $_POST['heads']);
if ($_POST['json'] != '') {
$headArray[] = 'Content-Type:application/json';
$postArray = $_POST['json'];
}
switch ($_POST['tip']) {
case 'POST':
curl_setopt($handle, CURLOPT_POST, 1);
curl_setopt($handle, CURLOPT_POSTFIELDS, $postArray);
break;
case 'GET':
$url .= '?' . http_build_query($postArray);
break;
default :
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $_POST['tip']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postArray);
}
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headArray);
$data = curl_exec($handle);
if ($data === false) {
echo 'Curl error: ' . curl_error($handle);
} else {
if($_POST['parsejson']) {
echo jsonbeautify(json_encode(json_decode($data), JSON_PRETTY_PRINT));
} else echo $data;
}
curl_close($handle);
function unserializeArea($data) {
$data = explode("\n", $data);
$res = [];
foreach ($data as $d) {
$d = explode('=', $d, 2);
$res[$d[0]] = $d[1];
}
return $res;
}
function jsonbeautify($data) {
$data = nl2br($data);
$data = str_replace(" ", "| *", $data);
$data = str_replace("*| ", "| ", $data);
$data = str_replace(" *", "--", $data);
echo $data;
}
?>