2013-06-30 140 views
1

我没有关于这个问题的具体问题,但更多的是,我不能开始工作,直到我知道这一点,不能挖掘一个答案,所以我会用一些随机片段我有躺在身边来示范。GM_xmlhttp请求通过代理服务器

说我有脚本:

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

如何着手对通过代理服务器的要求?


好吧,编辑,使之成为具体的问题:

我有一个包含

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

一个PHP页面,并使用我加载到一个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仍然是我自己的地址,所以它没有使用代理。 如何让它使用提供的代理服务器?

回答

0

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

通常对于ISP或公司代理服务商,根据您的提供商的说明提供set Firefox to use that proxyGM_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; 
    } 
}); 
+0

Soory我花了这么长时间才看到这一点,正是我所需要的,谢谢:) –

+0

不客气;乐意效劳。 –

相关问题