views:

221

answers:

0

hello,

i am writing a web proxy in C#, and i have noticed a difference between firefox and IE.

when my proxy catches requests from IE, i analyse the request - sometimes its a GET and sometimes its a POST. when it is a POST, i analyse the Content-Length field, and make sure this matches the actual content (the body), which is placed after the header.

so for example, the request might be something like this:

POST http://dss1.siteadvisor.com/DSS/MultiQuery HTTP/1.1
Accept: */*
Accept-Language: en-gb
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 
2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 
3.0.30618)
Host: dss1.siteadvisor.com
Content-Length: 5
Proxy-Connection: Keep-Alive
Pragma: no-cache

hello

so here we can see a header, stating that there are 5 bytes of data, and sure enough after the last header statement (the Pragma: no-cache bit) we have our 5 'hello' bytes.

the problem is that with IE7 there is no data. there is still the Content-Length statement, but no data. with Firefox i can see the Content-Length bit and then below, the data.

any ideas what the problem is ?

thank you.

[extra info] heres my code (stripped down a bit):

//catch a web browser request
TcpClient newClient = _tlsServer.AcceptTcpClient();
//read the request into a buffer
NetworkStream networkStream = newClient.GetStream();
networkStream.Read(buff, 0, buff.Length);
//convert to string
char[] chArray = new char[bytesSize];               
Array.Copy(buff, chArray, bytesSize);
sb.Append(chArray, 0, bytesSize);
string strRequest = sb.ToString();

so its the strRequest that contains the request string

once i have the strRequest string, i parse it to get various bits of info to instantiate a WebRequest object:

 WebRequest request = WebRequest.Create(strDestination);//i can get this by parsing strRequest
 request.Proxy = null;     
 request.Method = "POST";
 request.ContentLength = iContentLength;//i can get this by parsing strRequest 
 request.ContentType = strContentType;//i can get this by parsing strRequest
******* HERES THE PROBLEM - WHERE TO GET strData FROM ?? ******* 
     Stream dataStreamSend = request.GetRequestStream();
     byte[] byteArray = new byte[strData.Length];
     ASCIIEncoding enc = new ASCIIEncoding();
     byteArray = enc.GetBytes(strData);
     dataStreamSend.Write(byteArray, 0, byteArray.Length);
     dataStreamSend.Close();