试图从的GetResponse网站;
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();
}
}
}
此代码正在无线连接的Win7和LAN和Win8的任何而是在Win8和LAN错误不工作:需要407代理身份验证。 有没有什么解决办法。 谢谢。
尝试将代理凭据要求,也给网络凭据
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...
编辑
对于您创建的请求,您可以通过使用空代理您的要求禁用请求级别的自动代理检测
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
request.Proxy = null;
//rest of the code
WebProxy webProxy = new WebProxy("http://myproxy.net:8080/", true)
{
UseDefaultCredentials = false,
Credentials = new NetworkCredential("username", "pw")
};
请注意,正确的顺序设置属性{其他明智的失败对我来说}