Converting Raw HTTP Request into HTTPWebRequest Object

dr. evil picture dr. evil · Nov 25, 2008 · Viewed 26.6k times · Source

In .NET is it possible to convert a raw HTTP request to HTTPWebRequest object?

I'm sure .NET internally doing it. Any idea which part of the .NET is actually handling this? Can I call it or is there any external library which allows raw HTTP connections?

Answer

Ryan Cook picture Ryan Cook · Feb 10, 2009

I dont believe there is an exposed method to do this. You may have to find or write a parser to break the request up and then write your own class that extends HttpWebRequest.

Here is what looks like a parser from CodeProject:

http://www.codeproject.com/KB/IP/CSHTTPServer.aspx

I looked at the rotor code for the HttpWebRequest (briefly) and I did not see anything that stood out as a silver bullet. Here is the link to the file:

http://www.123aspx.com/Rotor/RotorSrc.aspx?rot=40844

All of the rotor code is here for browsing online:

http://www.123aspx.com/Rotor/default.aspx

And here you can download it:

http://www.microsoft.com/downloads/details.aspx?FamilyId=8C09FD61-3F26-4555-AE17-3121B4F51D4D&displaylang=en

I know a bunch of links doesn't really answer your question, but I don't think the functionality that you are looking for is exposed in the framework. I would love to be proven wrong, so please update the post if you find a good way of doing it. I know tools out there must do it, anything written in .Net that logs raw requests and then lets you resubmit them is doing something similar. I believe fiddler (http://www.fiddler2.com) is written in .Net, you may want to shoot an email over to those guys and see if they can help.