1

我对此还没有具体的问题,更重要的是,在我知道这一点并且无法找到答案之前我无法开始工作,所以我将使用我周围的一些随机片段来演示。

说我有脚本:

GM_xmlhttpRequest({
method: "GET",
url: server + "SyncWatcher/get.php?ckey=" + privatekey,
onload: function(response) {
document.getElementById("cfinder").innerHTML+="<span id='kswlst' style='display:none;'>" + response.responseText + "</span>";}});

还有一个随机代理服务器,比如说 188.2.38.197:8080

如何通过代理发出请求?


好的,进行编辑以使其成为特定问题:

我有一个 php 页面包含

echo $_SERVER['REMOTE_ADDR'] . "<br>" . $_SERVER['HTTP_X_FORWARDED_FOR'];

并使用以下命令将其加载到测试页面上的 div 中:

GM_xmlhttpRequest({
method: "GET",
url: "the get page",
proxy: "188.2.38.197",
port: "8080",
onload: function(response) {
document.getElementById("targin").innerHTML=response.responseText;
}
});

但是,它加载的 IP 仍然是我自己的地址,所以它没有使用代理。如何让它使用提供的代理服务器?

4

1 回答 1

0

没有proxy属性GM_xmlhttpRequest()。(也没有平原XMLHttpRequest()的。)

通常对于 ISP 或公司代理,您可以根据提供商的说明 将 Firefox 设置为使用该代理。GM_xmlhttpRequest()然后将自动使用该代理,只要目标站点不在 Firefox 的“无代理”列表中。

您的代码将是:

GM_xmlhttpRequest ( {
    method: "GET",
    url:    "AN ORDINARY URL THAT IS *NOT* IN THE 'NO PROXY' LIST",
    onload: function (response) {
        document.getElementById ("targin").innerHTML=response.responseText;
    }
} );

对于一次性或选择性使用的代理,它们通常通过 URL 参数或表单帖子获取目标 URL。您需要确定正在使用的代理的详细信息。

在这种情况下,您将指向代理URL,并提供适当的数据。
例如,假设您的代理接受GET请求并且配置如下:

Proxy IP:   188.2.38.197
Port:       8080
Path:       GimmeGimme
Parameter:  thisUrl

然后你会像这样获取你的页面:

var targetURL   = "http://YOUR_SERVER.COM/YOUR_PATH/";
var ajaxURL     = 'http://188.2.38.197:8080/GimmeGimme?thisUrl='
                + encodeURIComponent (targetURL)
                ;
GM_xmlhttpRequest ( {
    method: "GET",
    url:    ajaxURL,
    onload: function (response) {
        document.getElementById ("targin").innerHTML=response.responseText;
    }
} );
于 2013-07-12T08:05:24.250 回答