我使用下面的代码将标头发送到我指定的网站,该网站可以正常使用HTTP协议(端口= 80),但现在我尝试使用HTTPS(端口= 443)发送到标头。
mytcpclient = new TcpClient();
mytcpclient.Connect(host, port);
mysocket = mytcpclient.Client;
SendHeader(mysocket);
public void SendHeader(Socket mySocket)
{
String sBuffer = "";
sBuffer = sBuffer + "GET /"+pathquery+" HTTP/1.1" + "\r\n";
sBuffer = sBuffer + "Host: "+ hostname + "\r\n";
sBuffer = sBuffer + "Content-Type: text/html\r\n";
sBuffer = sBuffer + "\r\n";
Byte[] bSendData = Encoding.ASCII.GetBytes(sBuffer);
mySocket.Send(Encoding.ASCII.GetBytes(sBuffer), Encoding.ASCII.GetBytes(sBuffer).Length, 0);
}
我知道有SSLStream类,但我不确定如何重写代码,所以它使用SSL将头文件正确地发送到站点。