通过代理服务器GM_xmlhttpRequest

时间:2013-06-30 15:53:46

标签: javascript post proxy get greasemonkey

我对此没有具体的问题,更多的是我不能开始工作,直到我知道这个并且无法找到答案,所以我会使用一些我随意的随机片段演示。

说我有脚本:

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仍然是我自己的地址,所以它没有使用代理。 如何使其使用提供的代理服务器?

1 个答案:

答案 0 :(得分:0)

There is no proxy property for GM_xmlhttpRequest()。 (plain XMLHttpRequest()也没有。)

通常,对于ISP或公司代理,根据提供商的说明set Firefox to use that proxy。只要目标站点不在Firefox的“无代理”列表中,GM_xmlhttpRequest()就会自动使用该代理。

您的代码就是:

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。您需要确定正在使用的代理的详细信息。

在这种情况下,您可以指向 代理 网址,并提供相应的数据。
例如,假设您的代理接受了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;
    }
} );
相关问题