有没有办法通过 URL 参数设置代理?该脚本应该在 Ubuntu 服务器上运行。或者有可能用鱿鱼或类似的东西来完成吗?
喜欢http://proxyserver.com:3128/http://google.de
我已经尝试过一些 PHP 代理脚本,但它并没有真正发挥作用。它应该将文件作为流打开,但使用一些脚本加载整个文件,然后我得到一个输出,或者它不适用于 Safari 并且在每个浏览器上我都遇到了 javascript 的错误以获取流的信息。
可能这有帮助,为什么它不适用于 safari。我不知道如何编辑标题。设置接受范围等
最佳答案
另一个编辑
在这里试试这段代码。发布已实现。
$url = $_GET["url"];
$method = $_SERVER["REQUEST_METHOD"];
$data = array($_POST);
$options = array(
"http" => array(
"header" => "Content-type: application/x-www-form-urlencoded\r\n",
"method" => $method,
"content" => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$filter = "/(http|https|ftp|ftps)(:\/\/)/i";
$result = preg_replace($filter, "http://YOURDOMAIN.com/FOLDER/LOCATIONOFTHEPROXY.php?url=$1$2", $result);
echo $result;
var_dump($result);
编辑
Here我找到了一些使用 PhP 发布的代码。现在只需要实现它。
<?php
$url = "url to post to;
$data = array("comment" => "Testing PhP Post", "name" => "A PhP Script");
// use key "http" even if you send the request to https://...
$options = array(
"http" => array(
"header" => "Content-type: application/x-www-form-urlencoded\r\n",
"method" => "POST",
"content" => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
echo $result;
var_dump($result);
?>
你试过 file_get_contents()
了吗?
试试这个:
<?php
echo file_get_contents($_GET["url"]);
?>
使用类似 ?url=http://google.com/
的查询调用文件。
关于javascript - URL 参数代理脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35590131/