本文介绍了Web请求错误407代理服务器身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试的GetResponse从网站;
Trying to GetResponse From a web site;
using System.Text;
using System.Net;
using System.IO;
namespace DutyPharmacy751013
{
class Program
{
static void Main(string[] args)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Encoding encoding = Encoding.GetEncoding(response.CharacterSet);
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream, encoding);
string responseText= reader.ReadToEnd();
}
}
}
这code正在Win7和LAN
和Win8的任何无线连接
所需的407代理身份验证:但不会对win8的和LAN错误工作。
有没有什么解决办法。
谢谢你。
This code is working on win7 and LAN and on win8 and any of wireless connectionbut doesn't work on win8 and LAN error: 407 Proxy authentication required.Is there any solution.Thanks.
推荐答案
尝试添加代理凭据的要求,也给网络凭据
try with adding proxy credentials to request and also give network credentials
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
request.Credentials = new NetworkCredential("username", "pw");
WebProxy webProxy = new WebProxy("http://myproxy.net:8080/", true)
{
Credentials = new NetworkCredential("username", "pw"),
UseDefaultCredentials = false
};
request.Proxy = webProxy;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//rest of the code...
修改
对于您创建的,您可以在请求级别使用空代理您的要求禁用自动代理检测请求
Edit
For requests that you create, you can disable automatic proxy detection at the request level by using a null Proxy with your request
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
request.Proxy = null;
//rest of the code
这篇关于Web请求错误407代理服务器身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!