title: c# : how to implement server proxy support https?
body: <p>I am trying to redirect all requests from specific port (all of request come from Web Browser) to hostname of request as code</p>
  
  <p>1 - read all receive data from request</p>
  
  <pre><code>            while (recvRequest)
              {
                  this.clientSocket.Receive(requestBuffer);
                  string fromByte = ASCIIEncoding.ASCII.GetString(requestBuffer);
                  requestPayload += fromByte;
  
                  if (requestPayload.EndsWith(EOL + EOL))
                  {
                      recvRequest = false;
                  }
              }
  </code></pre>
  
  <p>2 - parse Query ( get host and Port and request type )</p>
  
  <pre><code>            HeaderFields = ParseQuery(requestPayload);
              if (HeaderFields == null || !HeaderFields.ContainsKey("Host"))
              {
                  return;
              }
              int Port;
              string Host;
              int Ret;
  </code></pre>
  
  <p>3 - if type equal CONNECT </p>
  
  <pre><code>            if (HttpRequestType.ToUpper().Equals("CONNECT"))
              { //HTTPS
                  Ret = RequestedPath.IndexOf(":");
                  if (Ret &gt;= 0)
                  {
                      Host = RequestedPath.Substring(0, Ret);
                      if (RequestedPath.Length &gt; Ret + 1)
                          Port = int.Parse(RequestedPath.Substring(Ret + 1));
                      else
                          Port = 443;
                  }
                  else
                  {
                      Host = RequestedPath;
                      Port = 443;
                  }
  
  
              }
  </code></pre>
  
  <p>4 - if type equal post or get</p>
  
  <pre><code>            else
              { //Normal HTTP
                  Ret = ((string)HeaderFields["Host"]).IndexOf(":");
                  if (Ret &gt; 0)
                  {
                      Host = ((string)HeaderFields["Host"]).Substring(0, Ret);
                      Port = int.Parse(((string)HeaderFields["Host"]).Substring(Ret + 1));
                  }
                  else
                  {
                      Host = (string)HeaderFields["Host"];
                      Port = 80;
                  }
                  if (HttpRequestType.ToUpper().Equals("POST"))
                  {
                      int index = requestPayload.IndexOf("\r\n\r\n");
                      m_HttpPost = requestPayload.Substring(index + 4);
                  }
              }
  
  
  
              requestPayload = "";
              foreach (string line in requestLines)
              {
  
                  requestPayload += line;
                  requestPayload += EOL;
              }
  </code></pre>
  
  <p>5 - connect to host</p>
  
  <pre><code>            Socket destServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
              destServerSocket.Connect(Host, Port);
              //State 2: Sending New Request Information to Destination Server and Relay Response to Client
              destServerSocket.Send(ASCIIEncoding.ASCII.GetBytes(requestPayload));
              //Console.WriteLine("Begin Receiving Response...");
  </code></pre>
  
  <p>6 - send Receiving Response   to client </p>
  
  <p>while (destServerSocket.Receive(responseBuffer) != 0)
                  {</p>
  
  <pre><code>                Console.Write(ASCIIEncoding.ASCII.GetString(responseBuffer));
                  this.clientSocket.Send(responseBuffer);
              }
  
              destServerSocket.Disconnect(false);
              destServerSocket.Dispose();
              this.clientSocket.Disconnect(false);
              this.clientSocket.Dispose();
  </code></pre>
  
  <p>but when i open email do not work correctly</p>