错误(407)QUOT;代理服务器身份验证和QUOT。 [英] error (407) "Proxy Authentication Required."
本文介绍了错误(407)QUOT;代理服务器身份验证和QUOT。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个要求像...我想从一个WinForms访问URL(登录页面,这是网络)。我有凭据传递给URL和反应应该是经过验证的网页(标记)。
的客户服务联系我写一个函数,将请求的URL和返回响应。但我得到的错误code(407)
代理服务器身份验证。
块引用>下面是我的code。
私有静态无效GetPageContent(){
字符串的URL =HTTPS://LoginPage.aspx/
HttpWebRequest的要求=(HttpWebRequest的)WebRequest.Create(URL);
request.Method =GET;
//如果服务器需要,设置凭据。
//request.Proxy.Credentials = CredentialCache.DefaultCredentials;
request.Credentials =新的NetworkCredential(用户1,testuser的#);
//得到响应。
HttpWebResponse响应=(HttpWebResponse)request.GetResponse();
//显示状态。
Console.WriteLine(response.StatusDescription);
//获取服务器返回包含流内容。
流数据流= response.GetResponseStream();
//打开使用容易获得一个StreamReader流。
StreamReader的读者=新的StreamReader(数据流);
//读取内容。
字符串responseFromServer = reader.ReadToEnd();
//显示的内容。
Console.WriteLine(responseFromServer);
//清理流和响应。
reader.Close();
dataStream.Close();
response.Close();
}
解决方案WebProxy代理=新WebProxy(proxyAddress);
proxy.Credentials =新的NetworkCredential(用户名,密码,域);
proxy.UseDefaultCredentials = TRUE;
WebRequest.DefaultWebProxy =代理;HttpWebRequest的要求=新的HttpWebRequest();
request.Proxy =代理;或者你可以使用
Web客户端
。Web客户端的客户端=新的WebClient();
client.Proxy =代理;
串downloadString = client.DownloadString(http://www.google.com);I have a requirement like...i want to access an url (login page which is web) from a winforms. i have to pass the credentials to that url and the response should be the contect of the authenticated web page(markup).
I have written a function which will request the url and return the response. but i am getting error code (407)
"Proxy Authentication Required."
Here is my code.
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(); }
解决方案WebProxy proxy = new WebProxy(proxyAddress); proxy.Credentials = new NetworkCredential("username", "password", "domain"); proxy.UseDefaultCredentials = true; WebRequest.DefaultWebProxy = proxy; HttpWebRequest request = new HttpWebRequest(); request.Proxy = proxy;
Or you could use
WebClient
.WebClient client = new WebClient(); client.Proxy = proxy; string downloadString = client.DownloadString("http://www.google.com");
这篇关于错误(407)QUOT;代理服务器身份验证和QUOT。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文