2
HttpGet request = new HttpGet("https://192.168.1.140:8732/...);

I wonder why I can only send successfully for custom headers : UserName and AuthToken if I do the following:

    request.setHeader("User-Agent", "android_client");
    request.setHeader("Host", "192.168.1.140:8732");
    request.addHeader("UserName", mUserName);
    request.addHeader("AuthToken", mAuthorizationToken);

Why is that this code NOT sending the UserName but AuthToken only? When the two bottom lines are reversed.

    request.setHeader("User-Agent", "android_client");
    request.setHeader("Host", "192.168.1.140:8732");
    request.addHeader("AuthToken", mAuthorizationToken);
    request.addHeader("UserName", mUserName);

Why is this code failing with 400 error code, invalid hostname when I don't specific the host

//  request.setHeader("User-Agent", "android_client");
//  request.setHeader("Host", "192.168.1.140:8732");
    request.addHeader("UserName", mUserName);
    request.addHeader("AuthToken", mAuthorizationToken);

If I don't need to send the UserName and AuthToken, I don't really need to set the Host and it works just fine with the code commented out like following

//  request.setHeader("User-Agent", "android_client");
//  request.setHeader("Host", "192.168.1.140:8732");

Though I don't think that it is related, I want to disclose that I am using self-signed certificate for these http call from android following this blog. Looking forward to the divine revelation for my poor http soul ...

Win Myo Htet
  • 5,377
  • 3
  • 38
  • 56
  • How do you know what is actually being sent? Did you examine the data stream with Fiddler? It will proxy HTTPS with a little configuration. – Jim Garrison Mar 15 '12 at 01:07
  • I also write the server side code in WCF C#. So I am aware of what is being sent. Using fiddler adding the two custom headers went through. It is only from those android client code, that is having issue. – Win Myo Htet Mar 15 '12 at 01:50
  • @Win Myo Htet: You can see what HTTP packets get sent access the wire by activating wire / context logging on the client side. You'll see whether or not all request headers are included in the request message. – ok2c Mar 15 '12 at 08:44

1 Answers1

0

It is a fluke. I couldn't reproduce it anymore. I have been working with the working solution and left it for a while working on different project. I come back and take a look with wire /context logging at oleg suggestion with the help of How to enable logging for apache commons HttpClient on Android I couldn't reproduce the problem anymore. The power of the logging has scared the problem away. Will update if the problem occurs again and if I find out the cause.

Community
  • 1
  • 1
Win Myo Htet
  • 5,377
  • 3
  • 38
  • 56