I am using the code below to send headers to the site I specify which works fine with HTTP protocol (port=80) but now I am trying to send to the headers using HTTPS (port=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);
}
I know there is SSLStream class but I am not sure how to rewrite the code, so it sends headers properly to the sites using SSL.
Use the Webclient class instead of TcpClient. It is made for http… See e.g http://www.dotnetperls.com/webclient