tags:

views:

99

answers:

4

This is the code I'm using, (taken largely from another online source, btw):

            string uri = "http://www.blah.com";
            // Create my request
            HttpWebRequest hwrOrdersIDCallback = (HttpWebRequest)WebRequest.Create(uri);
            hwrOrdersIDCallback.KeepAlive = false;
            hwrOrdersIDCallback.ProtocolVersion = HttpVersion.Version10;
            hwrOrdersIDCallback.Method = "POST";

            // Turn the req string into a byte stream
            byte[] postBytes = Encoding.ASCII.GetBytes(sbOrderIDsLine.ToString());

            // Set content type and stream length
            hwrOrdersIDCallback.ContentType = "application/x-www-form-urlencoded";
            hwrOrdersIDCallback.ContentLength = postBytes.Length;                

            Stream requestStream = hwrOrdersIDCallback.GetRequestStream();

            // Send the POST
            requestStream.Write(postBytes, 0, postBytes.Length);
            requestStream.Close();

            // Grab the response and display it in a label
            HttpWebResponse hwrOrdersIDResponse = (HttpWebResponse)hwrOrdersIDCallback.GetResponse();
            label1.Text = (new StreamReader(hwrOrdersIDResponse.GetResponseStream()).ReadToEnd());

I should be getting some specific data back from the server if the POST was completed successfully. I am NOT getting that data and I wanted to know if there was a way to see the information that is getting sent to the server by this POST.

+5  A: 

Do you absolutely have to investigate programmatically?

The easiest way to see what's going on is either to use Fiddler or WireShark.

Jon Skeet
I didn't know about "The World's Most Popular Network Protocol Analyzer" before. I just installed it, and it seems very powerful, but the amount of options are daunting. Fiddler was pretty intuitive for me for basic usage. Do you have a scenario where you would choose one over the other?
NerdFury
@NerdFury: Fiddler is only really for HTTP/HTTPS, and it's invasive in that by acting as a proxy, you may well change the actual behaviour of your app. (In particular it can cause problems if you're trying to debug another proxy server, or the behaviour of your app in the absence of proxies!) Where it *is* appropriate though, Fiddler is great - and its ability to do HTTPS is *very* handy.
Jon Skeet
+1  A: 

Fiddler2 is a great tool for debugging traffic for ajax/service calls. It monitors traffic, and you can view the details of the calls and see what data is posted and returned.

NerdFury
A: 

Use fiddler.

svinto
A: 

Create file named <your exe>.config in the application directory and place this inside it:

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <system.diagnostics>
     <trace autoflush="true" />
     <sources>
      <source name="System.Net">
       <listeners>
        <add name="System.Net"/>
                            </listeners>
      </source>
      <source name="System.Net.Sockets">
       <listeners>
        <add name="System.Net"/>
       </listeners>
      </source>
     </sources>
     <sharedListeners>
                    <add name="System.Net"
                             type="System.Diagnostics.TextWriterTraceListener"
                             initializeData="System.Net.trace.log"/>
     </sharedListeners>
     <switches>
      <add name="System.Net" value="Verbose" />
      <add name="System.Net.Sockets" value="Verbose" />               
     </switches>
    </system.diagnostics>
</configuration>

or use WireShark as others suggested. The trace technique is easier to setup, but harder to read.

Filip Navara
Thanks, everyone. Fiddler did the trick.