Search code examples
asp.netfiddler

Get HttpRequest like Fiddler


What's the easiest way to convert the entire HttpWebRequest to a single string. Similarly to what Fiddler displays when you switch the Fiddler's request pane to the Raw tab?

Thanks for your advice.


Solution

  • Use System.Net.WebClient.

    This code combines the HTTP Headers and Body for a Url similar to Fiddler:

    string url = "http://stackoverflow.com";
    var webClient = new System.Net.WebClient();           
    var body = webClient.DownloadString(url);
    var headers = webClient.ResponseHeaders.ToString();
    var raw = headers + "\r\n" + body;