How do I see the raw HTTP request that the HttpWebRequest class sends?

后端 未结 8 624
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 01:19

I know you are all going to answer \"use a debugging proxy server like Fiddler\" but it\'s not that simple.

Here\'s my situation: I have some code that runs on a ser

相关标签:
8条回答
  • 2020-11-29 01:46

    I suggest you to download Telerik Fiddler to capture incoming/outcoming traffic.

    Over here is simple example how to do it by that tool:

    1. Be sure that the Capture Traffic is enabled:
    2. Open browser and refresh the page, or just send request via HTTP client.
    3. After that switch to the Fiddler, you should see your request:
    4. At the top try to navigate “Raw” tab.
    5. In the below window is your raw request
    0 讨论(0)
  • 2020-11-29 01:47

    I know this is an old question, but I was in a tough spot where I didn't control the application config file, so I needed an easy way to enable the tracing via code and then easily access the raw request/response data in an event. So I put together this custom class, HttpRawTraceListener, which might be of use to others that are in my position:

    https://github.com/jhilgeman/HttpRawTraceListener/blob/master/HttpRawTraceListener.cs

    It was designed to be as simple as adding the file to your project, then calling:

    System.Diagnostics.HttpRawTraceListener.Initialize();
    

    ...to start the trace. From there, requests/responses will be parsed out of the trace messages and then be made available via the System.Diagnostics.HttpRawTraceListener.FinishedCommunication event.

    It's probably not 100% perfect for every scenario (e.g. it's not a proxy, so it won't capture web requests from a browser, for example), but it works pretty well for capturing HttpWebRequests requests/responses to web services, and it might be a good starting point if you need something like this.

    0 讨论(0)
提交回复
热议问题