Proxy server between web browser and web server

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey all, I'm trying to write a proxy server so that I can capture all data
sent from my web browser to any web server and then capture the response from
the server and send that back to the browser.

However, I've encountered a strange problem where the browser will not load
the data sent to it from my proxy server. I'm successfully able to capture
the data sent from the browser, then I'm able to capture the data sent back
from the web server, but when I try to send that data from the server to the
browser, the browser just sits there as if experiencing network lag.

However, if I just give the browser the first line or two of the data from
the server (and then tag on a carriage return) the browser gets it and stops
loading.

Here is the code that gets the response from the web server and sends it
back to web browser:
-----------------------
while (destStreamReader.Peek() != -1)
{
char [] charBuffer = new char[100];
int result = destStreamReader.Read(charBuffer, 0, 100);
currentInput = new String(charBuffer);
allTextFromInput += currentInput;

sourceStreamWriter.Write(currentInput);
currentInput = null;
}
sourceStreamWriter.Write("\r\n");
sourceStreamWriter.Flush();
sourceNetworkStream.Flush();
-----------------------

I used to just get the data via the WriteLine method, but I changed it to
this way because I thought there might be a problem with the quantity of data
that was being transmitted on each line.

If I only grab the first few 100 characters of data the browser at least
stops loading.

Any suggestions as to why this isn't working?

Thanks,
Novice
 
Novice,

Are you using the correct encoding on the stream reader and writer?
Also, where are you getting the stream for the response? If you are not
getting the headers, and passing them along, then the browser might not know
what to do with the content you send back.

Also, you should be able to copy the byte stream back byte for byte,
there is no reason to convert it to a character array.

Hope this helps.
 
Back
Top