我們有一個我們想通過代理服務器使用的後臺操作(Window服務)。將C#WebClient與代理服務器結合使用 - 對代理服務器沒有請求?
基本上,我們這樣做:
public WebClient GetWebClient(){
var webClient = new WebClient();
webClient.proxy = new WebProxy(Configuration.ProxyHost, Configuration.ProxyPort);
// add a bunch of headers to the WebClient (sessionids, etc.)
return webClient;
}
代理是一個我們已經使用FreeProxy配置自己。
我已啓用日誌記錄功能,並在我正在測試的計算機上運行,並且可以確認在Firefox中使用該代理服務器時正在對該代理服務器發出請求。
代理服務器不需要身份驗證,但IP必須在我們的辦公室(從Firefox證據來看,我認爲這不是問題)。
然而,我們的後臺進程中,我似乎不被使用代理,當我使用Web客戶端:
using(var wc = GetWebClient())
using(var s = wc.OpenRead("someurl"))
using(var sr = new StreamReader(s)){
return sr.ReadToEnd();
}
我沒有收到來自但是,代理錯誤,好像我們只是即使代理已經明確設置,也沒有它。
該信息似乎沒有問題,只是不通過我們的代理。
使用WebClient
代理服務器時是否有某些我丟失?
編輯:更多細節。如果我們禁用服務器上的代理服務,那麼我們會得到一個我們無法連接的異常。所以看起來web客戶端正試圖接觸到代理服務器,但該流量實際上並未流經代理服務器。
Inner Exception: SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
我手動設置代理,如圖第一方法片段。我在這裏錯過了什麼嗎? – ddango
對不起,我完全忽略了這一點!讓我檢查休息後的任何問題 – Polity