title: App to Web API Yields 400 Invalid Hostname
body: <p>I have a strange problem.  From my android app, I'm calling an ASP.NET Web API.  I can make a POST request with no problem from the app.  However, when I go to make a GET request, the request returns "400 bad request invalid hostname".  This is strange as I can make a POST request, not a get.  The URL I'm using is <code>http://10.0.2.2/webapp/api/controllername</code> (10.0.2.2 because android emulator uses 127.0.0.1; this is a published workaround).  I do have the internet permission enabled.</p>
  
  <p>I have the web API currently debugging, and I can debug the post requests.  I can manually type in the URL in Internet Explorer for the get request, and hit the server.  This is how I know it's working.  I have a handler for application_beginrequest just to see that I am even hitting the server, and it is for the post requests.  But I never even see a get request come in to the server.</p>
  
  <p>To make the Android GET request, I utilized the following (added comments with additional information).</p>
  
  <pre><code>//Creation of get request
  HttpGet request = new HttpGet(url); //correct URL; verified
  for(NameValuePair h : headers)
  {
      //6 headers added; verified OK
      request.addHeader(h.getName(), h.getValue());
  }
  //Calls method shown below
  return executeRequest(request, url);
  
   private ResponseInformation executeRequest(HttpUriRequest request, String url) throws Exception
  {
      HttpClient client = new DefaultHttpClient();
      HttpResponse httpResponse;
  
      try {
          //Get the response and check the code/message
          httpResponse = client.execute(request);
          responseCode = httpResponse.getStatusLine().getStatusCode();
          message = httpResponse.getStatusLine().getReasonPhrase();
  
          HttpEntity entity = httpResponse.getEntity();
          ResponseInformation info; // just a DTO for my needs
  
          if (entity != null) {
              InputStream instream = entity.getContent();
              //Response is an XML document listing the 400 error information
              response = convertStreamToString(instream);
              info = new ResponseInformation(responseCode, response, message);
              instream.close();
          }
          else
              info = new ResponseInformation(responseCode, message);
  
          return info;
  
      }
      .
      .
  }
  </code></pre>
  
  <p>So I'm not sure who is doing the rejecting?  Why would I get this error?  It never hits Application_BeginRequest so it never makes it to my web API service, but POSTS do... so strange.</p>