Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用WebProxy时HttpWebRequest的奇怪行为_C#_Proxy_Httpwebrequest_Httpwebresponse_Webproxy - Fatal编程技术网

C# 使用WebProxy时HttpWebRequest的奇怪行为

C# 使用WebProxy时HttpWebRequest的奇怪行为,c#,proxy,httpwebrequest,httpwebresponse,webproxy,C#,Proxy,Httpwebrequest,Httpwebresponse,Webproxy,我有一个带有StreamReader的HttpWebRequest,它在不使用WebProxy的情况下工作得非常好。当我使用WebProxy时,StreamReader读取奇怪的字符,而不是实际的html。这是代码 HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://URL"); req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleW

我有一个带有StreamReader的HttpWebRequest,它在不使用WebProxy的情况下工作得非常好。当我使用WebProxy时,StreamReader读取奇怪的字符,而不是实际的html。这是代码

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://URL");
req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10";
req.Accept = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
req.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
req.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
req.Headers.Add("Accept-Language", "en-US,en;q=0.8");
req.Method = "GET";
req.CookieContainer = new CookieContainer();

WebProxy proxy = new WebProxy("proxyIP:proxyPort");
proxy.Credentials = new NetworkCredential("proxyUser", "proxyPass");
req.Proxy = this.proxy;
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(res.GetResponseStream());
string html = reader.ReadToEnd();
在不使用
WebProxy
的情况下,变量
html
保存来自URL的预期html字符串。但是对于
WebProxy
html
持有这样的值:

"�\b\0\0\0\0\0\0\0��]R����s�Y����\0\tP\“]ki���ػ��-��X�\0\f���/�!�胡���>铬���P$%�天然橡胶�� Z�G��3.�T�~第三季度�ٵȋ(M)���14和?\r�d:�前任�J��P������.��Y��o�|��ӎu�面向对象。�����\v] ?}�~������E:�B��Lן�Ԙ6+�L���岳�Y��y'ͧ��~#5ϩ�信息技术�2.��5.��%�P��E�L����t&x0:-�2.��我�C���$M��_6.��祖�t、 J�>C-��GY��K�O�R$�P�T��8+�*]“为什么?”���$<代码>Ō�-�R�ʙ�H3\f8Jd���Q(:�G�E���R���Rܔ�ڨ�����W�8\b�P� �\= 4\f�> �&��$��\v��C��C�风险投资��x�P�|\"b9�ʤ�\r%i��w@��\T�R�M�� �����!�G�太平绅士�8.D�K�Xʹt�J��/\v�R��y\f7因为您要通过

req.Headers.Add("Accept-Encoding", "gzip,deflate,sdch"); 
我想说,在将流发送回您之前,您的代理将压缩流

检查响应的标题以检查编码。

因为您正在传递

req.Headers.Add("Accept-Encoding", "gzip,deflate,sdch"); 
我想说,在将流发送回您之前,您的代理将压缩流


检查响应的标题以检查编码。

只需使用Gzip对其进行解压缩。

只需使用Gzip对其进行解压缩。

HttpWebRequest
甚至不支持sdch.:
HttpWebRequest
甚至不支持sdch.)