我有一個要求...我想從一個winforms訪問一個URL(登錄頁面是網頁)。我必須將憑據傳遞給該URL,並且響應應該是經過身份驗證的網頁(標記)的標記。錯誤(407)「需要代理驗證」。
我寫了一個函數,它會請求url並返回響應。但我得到錯誤代碼(407)
「需要代理驗證」。
這是我的代碼。
private static void GetPageContent(){
string url = "https://LoginPage.aspx/";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
// If required by the server, set the credentials.
//request.Proxy.Credentials = CredentialCache.DefaultCredentials;
request.Credentials = new NetworkCredential("user1", "testuser#");
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Display the status.
Console.WriteLine(response.StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
}
嗨安妮,什麼是proxyAddress? – Tim
我通過uri作爲代理地址,但仍然出現錯誤。但這次是因爲「ServicePointManager不支持使用https方案的代理。」 – Tim
確保網址前綴爲「http://」。參考[this](http://blogs.msdn.com/b/jpsanders/archive/2007/04/25/the-servicepointmanager-does-not-support-proxies-of-https-scheme-net-1- 1-sp1.aspx)和[this](http://stackoverflow.com/questions/954635/the-servicepointmanager-does-not-support-proxies-of-scheme) –