0
TcpClient 및 SslStream을 사용하여 서버에 https 요청을 보내고 있는데 일반적으로 작동하며 헤더가 일반 텍스트로 돌아 오는 것을 볼 수 있지만 페이지 내용은 횡설수설합니다. 내가 뭘 잘못하고 있는지 모르겠다. 콘솔에 기록SslStream 암호 해독 문제가 있습니까?
using (var client = new TcpClient("host", 443))
{
using (var sslStream = new SslStream(client.GetStream(), true, null, null, EncryptionPolicy.AllowNoEncryption))
{
sslStream.AuthenticateAsClient("host", null, SslProtocols.Tls, false);
using (var writer = new StreamWriter(sslStream))
using (var reader = new StreamReader(sslStream))
{
writer.AutoFlush = true;
writer.WriteLine("GET/HTTP/1.1");
writer.WriteLine("Host: host:443");
writer.WriteLine("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0");
writer.WriteLine("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
writer.WriteLine("Accept-Language: en-US,en;q=0.5");
writer.WriteLine("Accept-Encoding: gzip, deflate");
writer.WriteLine("Referer: host");
writer.WriteLine("Connection: close");
writer.WriteLine();
writer.WriteLine();
Console.WriteLine(reader.ReadToEnd());
}
}
}
예 결과 :
HTTP/1.1 200 OK
Server: Apache/2.2.15 (Red Hat) Phusion_Passenger/3.0.17
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.17
ETag: "d313c66ae97b1bf4fa81ce11830a40d2"
Content-Language: en
X-Runtime: 3095
Cache-Control: private
Status: 200
Content-Encoding: gzip
P3P: CP="NON DSP CURa ADMa DEVa TAIa PSAa PSDa IVAa IVDa CONa TELa OUR DELa SAMa OTRa IND PHY ONL UNI PUR FIN COM NAV INT CNT STA PRE LOC"
Content-Length: 43543
Content-Type: text/html; charset=utf-8
Date: Sat, 27 Jul 2013 05:41:13 GMT
Connection: close
Vary: Accept-Encoding
? ???v?H?(
?n?u???S??.J???????U?ZR??o-?$?Q6 Jf????~?p_?F$ ?!?"??Z?Df?SF???????/??B?????N?
;????????????n?NiO???s?????a??$??????0???????H??????;??w?t???????_????0