[PHP] 纯文本查看 复制代码 <?php
// 当前文件: test.php
$info = $_SERVER;
// 验证参数是否以 url 开头
$string = $info['QUERY_STRING'];
$query = 'url=';
if (substr($string, 0, strlen($query)) !== $query) die("罢了");
// 请求类型
$type = $info['REQUEST_METHOD'];
$content_type = $info['CONTENT_TYPE'] ? "Content-Type: {$info['CONTENT_TYPE']}\r\n" : "";
$request_url = $info['REQUEST_URI'];
$keyword = ".php?url=";
$offset = strlen($keyword);
$url = substr($request_url, strpos($request_url, $keyword) + $offset);
$url = str_replace('.php&', ".php?", $url);
// 请求头
$header = "$content_type \r\n";
$data = file_get_contents("php://input");
function request($url, $type, $data, $header)
{
$opts = [
'http' => [
'method' => $type,
'header' => $header,
'content' => $data
]
];
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
print_r($result);
}
// post(请求地址, 请求方式, 请求体数据, 请求头)
request($url, $type, $data, $header);
|