2

When I enter either this URI to call a REST method on my running Web API app:

http://SHANNON2:21608/api/inventory/sendXML/duckbill/platypus/someFileName // using Hostname of local machine

--or this one:

http://192.168.125.50:21608/api/inventory/sendXML/duckbill/platypus/someFileName // using IP Address of local machine

...in Postman (using HttpPost, and attaching an xml file) and run it, on examining it in Fiddler 2, I see this error in Fiddler's Inspectors.WebView pane:

Bad Request - Invalid Hostname

--------------------------------------------------------------------------------

HTTP Error 400. The request hostname is invalid.

Note: I get that error even though I do hit the breakpoint in the corresponding Controller REST method on the server.

Trying to examine further exactly what's happending (what HTTP is being sent), I run Wireshark and see only this for destination of my IP Address:

enter image description here

...and this with my IP Address as the source:

enter image description here

Why are there no HTTP Protocol entries? The HTTP is apparently being sent, because I am hitting the breakpoint I've set on the first line in the server Controller method:

[HttpPost]
[Route("api/inventory/sendXML/{userId}/{pwd}/{filename}")]
public async Task SendInventoryXML(String userId, String pwd, String fileName)
{
    Task task = Request.Content.ReadAsStreamAsync().ContinueWith(t =>
    {
        var stream = t.Result;
        using (FileStream fileStream = File.Create(String.Format(@"C:\HDP\{0}.xml", fileName), (int)stream.Length))
        {
            byte[] bytesInStream = new byte[stream.Length];
            stream.Read(bytesInStream, 0, (int)bytesInStream.Length);
            fileStream.Write(bytesInStream, 0, bytesInStream.Length);
        }
    });
}

So why is Wireshark being so secretive about showing me the HTTP sent? Is it turning a blind eye to that internal communication and, if so, how can I "unleash it" to show me that?

UPDATE

Aha / Voila! A combination of Postman, RawCap (http://www.netresec.com/?page=RawCap), and Wireshark seems to work. I promptly ran the newly-discovered RawCap from a command prompt with this verbiage:

RawCap.exe 192.168.125.50 captured.pcap

...then called the REST method from Postman, and opened the resulting file that RawCap created (captured.pcap in my case) in Wireshark, and it shows me some HTTP traffic:

enter image description here

Some more detail about the HTTP call can be seen here:

enter image description here

What I don't know is how to "shut down" RawCap gracefully.

UPDATE 2

RawCap/Wireshark tell me it's a Bad Request (which I already knew was the response):

enter image description here

...but I see nothing to give me a clue about why it's considered a bad request

UPDATE 3

When I try to call my REST method from Fiddler Composer with all the various forms of "local" (hostname, IP Address, "locohost"), I never reach the breakpoint in the server; I get err msgs prior to that (404 for locohost, 400 for all others):

enter image description here

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 1
    possible duplicate of [Wireshark localhost traffic capture](http://stackoverflow.com/questions/5847168/wireshark-localhost-traffic-capture) – Jim Lewis Sep 09 '14 at 19:33
  • I don't think it's quite the same; in my case, I'm seeing traffic for my local machine (using the IP Address), but I'm just not seeing some HTTP traffic that should be there/visible. – B. Clay Shannon-B. Crow Raven Sep 09 '14 at 20:30
  • 1
    Are you certain that the requests and responses are going over HTTP over TCP, rather than HTTP over SSL/TLS over TCP? The Wireshark traffic shows TLSv1 traffic, which you'd see if it's HTTP over TLS over TCP. I think Fiddler might intercept the traffic *before* it's encrypted by SSL/TLS. –  Sep 09 '14 at 20:57
  • @GuyHarris: All down but nine; set 'em up on the other alley, pard. – B. Clay Shannon-B. Crow Raven Sep 09 '14 at 20:58
  • 1
    The Content Length of the error response is 334 bytes...what does the message body contain? Do you have a trace of a successful invocation that you can compare to? – tcarvin Sep 10 '14 at 11:55
  • 1
    ...and speaking of content length, why does your POST show a content length of 0? – tcarvin Sep 10 '14 at 11:56
  • @tcarvin: I don't know; I've added a file to be sent. – B. Clay Shannon-B. Crow Raven Sep 10 '14 at 15:14
  • Tip on using RawCap with Wireshark here: http://www.codeproject.com/Tips/819121/How-to-Capture-and-View-Local-Network-Traffic – B. Clay Shannon-B. Crow Raven Sep 15 '14 at 21:03

1 Answers1

2

Typically, Invalid Hostname means that the HTTP request's Host header contains a value that is not bound to any site on the web server. For instance, you're using an IP address as the host, but if your server is only configured to accept a machine name (e.g. mybox) then you will see a HTTP/400 from the server demanding that you supply a proper hostname.

EricLaw
  • 56,563
  • 7
  • 151
  • 196
  • Testing it from Postman and Fiddler Composer, the only thing that hits the breakpoint in the server's Controller code is "localhost"; the IP Address doesn't work, neither does the Hostname. Where do I need to look in the Server to see how it's configured this way? – B. Clay Shannon-B. Crow Raven Sep 10 '14 at 20:53
  • What server are you running on? The VS Dev server binds *only* to `localhost`. If you're running a full IIS instance, use the server manager to bind additional hostnames. – EricLaw Sep 10 '14 at 22:34
  • I reckon that's my problem - the server app is running from VS 2013 on my dev machine. This uses IIS Express, right? By "a full IIS instance" I reckon you mean something "mightier" than that? – B. Clay Shannon-B. Crow Raven Sep 10 '14 at 22:39
  • 1
    Yes, `full IIS instance` like IIS running on Windows Server. See http://stackoverflow.com/questions/5235826/using-iis-express-to-host-a-website-temporarily if you want to use a non-`localhost` hostname. – EricLaw Sep 11 '14 at 00:46