10317

Get request text

I have a HttpWebRequest:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(methodUrl.ToString()); req.Method = "POST"; string postData = Serializer.Serialize(GetAllFields()); req.ContentType = @"application/json; charset=utf-8"; req.Accept = @"application/json; charset=utf-8"; ...

And I would like to see the actual raw request before it's sent. (req.ToString() only gives the req's type) I came to conclusion I should use Stream somehow, but I can't understand how..

How can I get the my web request's headers and body before it's sent?

<strong>Added:</strong> I ultimately want something like:

string requestAsText= //some method that will give me the whole post text.

Thanks.

Answer1:

Add these to your config file and this will pretty much dump every communication (this saves to network.log file):

<system.diagnostics> <sources> <source name="System.Net" tracemode="includehex" maxdatasize="1024"> <listeners> <add name="System.Net"/> </listeners> </source> <source name="System.Net.Sockets"> <listeners> <add name="System.Net"/> </listeners> </source> <source name="System.Net.Cache"> <listeners> <add name="System.Net"/> </listeners> </source> </sources> <switches> <add name="System.Net" value="Verbose"/> <add name="System.Net.Sockets" value="Verbose"/> <add name="System.Net.Cache" value="Verbose"/> </switches> <sharedListeners> <add name="System.Net" type="System.Diagnostics.TextWriterTraceListener" initializeData="network.log" /> </sharedListeners> <trace autoflush="true"/> </system.diagnostics>

http://msdn.microsoft.com/en-us/library/ty48b824.aspx

Recommend

  • Why multiply the error by the derivative of the sigmoid in neural networks?
  • Find lines in shape
  • How is SLOC counted by Delphi IDE?
  • Laravel lmutator $this->attributes return 'Undefined index: id'
  • How to set an entity field that does not exist on the table but does exists in the raw SQL as an ali
  • Count from each distinct date, fill in missing dates with zero
  • Unzip archive in .Net CORE 1.0
  • Streaming screenshots over WebRTC as a video stream from iOS
  • Using Generics on right hand side in Java 6?
  • Salesforce Different WSDL files and when to use
  • How to convert SOAP response with xsi values to json in WSO2esb
  • saving file generated by TCPDF
  • presentShareDialogWithParams posts to FB wall, but callback handler results say error
  • Alternative To body {overflow:scroll;} That Will Prevent Page Jostling/Wriggling?
  • Installing Apache MyFaces 2 on WildFly 8.2.0
  • Hardware Accelerated Image Scaling in windows using C++
  • Time complexity of a program which involves multiple variables
  • Content-Length header not returned from Pylons response
  • Play WS (2.2.1): post/put large request
  • Bad request using file_get_contents for PUT request in PHP
  • Checking free space on FTP server
  • Reading JSON from a file using C++ REST SDK (Casablanca)
  • Using jQuery closest() method with class selector
  • FB SDK and cURL: Unknown SSL protocol error in connection to graph.facebook.com:443
  • Array.prototype.includes - not transformed with babel
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • Symfony2: How to get request parameter
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • Is there a mandatory requirement to switch app.yaml?
  • log4net write single file for each call to log.info
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • Getting error when using KSoap library to consume .NET web services
  • How do I configure my settings file to work with unit tests?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Can't mass-assign protected attributes when import data from csv file
  • Binding checkboxes to object values in AngularJs
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS