를 사용하는 동안 나는 WebProxy가를 사용하지 않고 매우 잘 작동에서는 StreamReader와 함께 HttpWebRequest를있다. WebProxy를 사용할 때 StreamReader는 실제 html 대신 이상한 문자를 읽습니다. 여기에 코드가 있습니다. WebProxy
를 사용하지 않고이상한 행동 WebProxy가
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();
는 변수 html
는 URL에서 예상되는 HTML 문자열을 보유하고 있습니다. 그러나 WebProxy
와 html
그런 값 보유 :
"\의 B를 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0] rsY \ 0 \ tP \ "] ki ػ 0 0 0 0 0 0 0 0 0 $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 3t ~ 3 분기 اٴ ȋ (M14 & \ RD : exj p.Yo | ӎuOO . \ v]?} ~ E : b L Ԙ6 + l 岳 Y y'ͧ ~ # 5ϩ it 2 5 % 펠트 & X0 : -2iC $ M_6zUtJ> C-GY k O R P T 8 + *] HY \ " $
Ō�-�r�ʙ
H3 \ f8Jd Q (: GErR ܔ ڨ W <] $ I> 8 \ BP \ = 4 \ F> $ & \ v C C vC x p "b b ʤ G jP 8D k X't J /\ v! r y \ f7 < \ ", \ a/IK r ҿ5;} H + QIO] 8cnAG ڟ U2>
Perfect. 헤더를 제거하면 작동합니다. 감사 샘. – deadlock
'HttpWebRequest'는 sdch도 지원하지 않습니다. :) – bzlm