我有一个要求...我想从一个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) –