Adding multiple custom http request headers mystery


HttpGet request = new HttpGet(";

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", ""); 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", ""); 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", ""); 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", "");

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 <a href="http://blog.antoine.li/2010/10/22/android-trusting-ssl-certificates/" rel="nofollow">blog</a>. Looking forward to the divine revelation for my poor http soul ...


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 <a href="https://stackoverflow.com/users/335638/oleg" rel="nofollow">oleg</a> suggestion with the help of <a href="https://stackoverflow.com/questions/3246792/how-to-enable-logging-for-apache-commons-httpclient-on-android" rel="nofollow">How to enable logging for apache commons HttpClient on Android</a> 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.


  • Single word Palindrome Checker (True or False)
  • Edge-case: When (only) reversing order of template parameters in specialization, can non-specialized
  • How can I write a recursive function to reverse a linked list?
  • passing parameter to server in ExtJs
  • CUDA Debugging - VS on windows workstation, GPUs on Linux server?
  • Single django queryset to get n adjacent items
  • MAVEN : Run Multiple Maven Project using Maven Test
  • retrieving data from url in iphone
  • How can I prevent the need to copy strings passed to a avr-gcc C++ constructor?
  • Enumerating Controls on a Form
  • How to log in to an HTTPS website with Jsoup?
  • order post according to custom array position
  • 550 Access denied - Invalid HELO name
  • Word Open XML Mail Merge
  • Meteor: Do Something On Email Verification Confirmation
  • why do I get the error when installing the gem 'pg'? [duplicate]
  • Avoid links criss cross / overlap in d3.js using force layout
  • SignalR .NET Client Invoke throws an exception
  • Using variable in a value field in jMeter
  • R - Combining Columns to String Based on Logical Match
  • Using $this when not in object context
  • What is the “return” in scheme?
  • Read text file and split every line in MSBuild
  • Array.prototype.includes - not transformed with babel
  • Volley JsonObjectRequest send headers in GET Request
  • Accessing IRQ description array within a module and displaying action names
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Build own AppleScript numerical error handling
  • Websockets service method fails during R startup
  • Google cloud sdk not working when python points python3
  • Return words with double consecutive letters
  • how to add data labels for bar graph in matlab
  • Is there a mandatory requirement to switch app.yaml?
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Linking SubReports Without LinkChild/LinkMaster
  • How can I remove ASP.NET Designer.cs files?
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • java string with new operator and a literal