2

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?

jiduvah
  • 5,108
  • 6
  • 39
  • 55

1 Answers1

1

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.

Community
  • 1
  • 1
Eliezer
  • 7,209
  • 12
  • 56
  • 103
  • That method is part of the apache commons library. I am using DefaultHttpClient in the android library – jiduvah May 22 '12 at 11:37
  • We worked around it on the server side. I marked you as correct as its not so clear that its default behaviour – jiduvah May 22 '12 at 11:40
  • I'm pretty sure that the Android library's DefaultHttpClient is the one from Apache – Eliezer May 22 '12 at 12:20
  • That was my first thought but on further reading this.. http://stackoverflow.com/questions/2618573/what-version-of-apache-http-client-is-bundled-in-android-1-6 suggests google don't follow any released versions of the apache library. The class is linked to on the your post isn't in the Android library – jiduvah May 22 '12 at 15:31
  • What a headache...In any case this could still be the underlying issue regardless of the authorship of the code unless someone has a better idea of what it could be – Eliezer May 22 '12 at 16:18