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 ...

3
  • 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. Commented Mar 15, 2012 at 1: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. Commented Mar 15, 2012 at 1: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. Commented Mar 15, 2012 at 8:44

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.