我的想法是这种的,模拟写一个浏览器的通讯功能,不需要什么渲染功能;
单单实现 TCP/IP 对接 Web 服务器的通信,从而获取到响应的 HTML 代码。
Http:80 端口的已实现了,就是 Https 这里不太理解;
按照正常逻辑,Https 采用的对称加密方式,首次 TCP 握手成功后,
服务器会响应一个公钥,但是我用 TCP 写的时候,直接返回 HTML 代码了。
代码如下:
// User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleW....
Sockets.TcpClient tcpClient = new Sockets.TcpClient();
tcpClient.Connect(ip, 80);
string sendContents =
@"GET {0} HTTP/1.1
Host: {1}
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8
"; // 注意,这里需要多一个 \r\n
sendContents = string.Format(sendContents, path, host);
byte[] sendBuffer = Encoding.UTF8.GetBytes(sendContents);
tcpClient.Client.Send(sendBuffer, sendBuffer.Length, Sockets.SocketFlags.None);