I am working on an app with communicates with our server. There is a bug in one of the libraries on the server side. This bug makes it a requirement to send the port along with the host.
The problem is that when I am sending a request the port seems to be striped out. I was originally using HTTPClient and setting the header like so
httpClient.addHeader(new BasicHeader("Host", "company.net:80"));
but server side they only received “company.net”
I also tried using an requestInterceptor like so
httpClient.addRequestInterceptor(new HttpRequestInterceptor() {
public void process(
final HttpRequest request,
final HttpContext context) throws HttpException, IOException {
request.setHeader("Host", "company.net:80");
Log.i(TAG, "intercepted and set host header");
}
});
But alas, the same problem occurred.
My final attempt was to use URLConnection instead of httpClient
urlConnection.addRequestProperty("Host", "company.net:80");
You can probably guess the outcome.
How do I send the host including the port?
This seems to be the default behavior of
HttpClient(see here) in that it sets the host header to the host you are actually sending it to right before it sends the request. Since port 80 is the default HTTP port, it doesn’t include it in its version of Host. You could try the method in the link and see if that does it for you.