C# IE代理可以上,但是HttpWebRequest却连不上
本人在公司用代理上网,对于一个网址,用IE设置代理,可以上,但是编写程序用HttpWebRequest设置代理却总是返回超时,请高手指点:
byte[] byteRequest = Encoding.Default.GetBytes(postData);
HttpWebRequest httpWebRequest;
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.CookieContainer = cookieContainer;
httpWebRequest.ContentType = contentType;
httpWebRequest.Referer = url;
httpWebRequest.Accept = accept;
httpWebRequest.UserAgent = userAgent;
httpWebRequest.Method = isPost ? "POST" : "GET";
httpWebRequest.ContentLength = byteRequest.Length;
WebProxy loProxy = WebProxy.GetDefaultProxy();
httpWebRequest.Proxy = loProxy;
Stream stream = httpWebRequest.GetRequestStream();
stream.Write(byteRequest, 0, byteRequest.Length);
stream.Close();
HttpWebResponse httpWebResponse;
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, encoding);
string html = streamReader.ReadToEnd();
streamReader.Close();
responseStream.Close();
请大侠指点问题。。。。
------解决方案--------------------WebProxy loProxy = WebRequest.GetSystemWebProxy();
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
http://feiyun0112.cnblogs.com/
------解决方案-------------------- httpWebRequest.Proxy = System.Net.WebRequest.GetSystemWebProxy();
看看.
------解决方案--------------------System.Net.WebProxy oWebProxy = new System.Net.WebProxy("IP", 8080);