There is a task - to write a simple proxy server. Well, this task is 'almost' completed. I think i'm re-inventing the wheel but I don't mind, my proxy works like this:


There's a HttpListener that listens and launches a processing thread at web request of a client. Then the processing thread forms a WebRequest to the necessary site, downloads its contents, removes all the flash, tops, counters and adclicks and returns it all to the client.


As I said this 'almost' works. The problems start when I need to get an authorization on some resource (web mail or forum or whatever).

So, the first question is whether am I doing everything right with cookies:

vb Code:
  1. Dim CookieCont As CookieContainer = Nothing
  2.         If DownStream_Request.Cookies.Count <> 0 Then
  3.             CookieCont = New CookieContainer
  4.  
  5.             Dim c As Cookie
  6.             For Each c In DownStream_Request.Cookies
  7.                 If c.Domain = "" Then
  8.                     c.Domain = UB.Host
  9.                 End If
  10.                 CookieCont.Add(c)
  11.             Next
  12.         End If
  13.  
  14.         UpStream_Request.CookieContainer = CookieCont
The second question - I'm not sure if I process POST requests right:

vb Code:
  1. If DownStream_Request.HttpMethod.ToLower = "post" Then
  2.  
  3.                 UpStream_Request_Stream = UpStream_Request.GetRequestStream
  4.                 DownStream_Request_Stream = DownStream_Request.InputStream
  5.  
  6.                 Do
  7.                     bytesRead = DownStream_Request_Stream.Read(buffer, 0, buffer.Length)
  8.                     UpStream_Request_Stream.Write(buffer, 0, bytesRead)
  9.                     If bytesRead = 0 Then
  10.                         UpStream_Request_Stream.Flush()
  11.                         UpStream_Request_Stream.Close()
  12.                         DownStream_Response.Redirect(requested_uri.ToString)
  13.                         DownStream_Response.Close()
  14.                         ThreadCol.Remove(mythread)
  15.                         Exit Sub
  16.                     End If
  17.                 Loop
  18.             End If

Anyway, I don't understand what else should I do in order to get authorizations on forums and mail work properly.