javascript - URL 参数代理脚本

标签 javascript php linux ubuntu proxy

有没有办法通过 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/

相关文章:

php - 我的 .php/?PHPSESSID=xxxxxxxxxxxxxxxxxx 出现意外响应代码 500

linux - 在 df 输出命令上为每一行添加时间戳?

linux - 如何在 CentOS 6 上升级到 CouchDB 1.3.0+?

Linux 内核模块 : Delayed workqueue make the kernel crashed

javascript - 如何获取所选选项的值(value)?

Javascript 将 html 表导出到 Excel

php - 在 mysql 查询中使用 php 数组

php - Sendgrid 错误 400 错误请求

javascript - 当服务器关闭/崩溃时,Node JS 自动重启所有永远的 JS 进程

javascript - 在 raphaeljs 中画一个轮子