Question

How can I request jboss server virtual host by ip with HTTPUrlConnection or other connection type?

What I tried: - Add header to http request with virtual host alias (Host:jboss.local.virtual.host) - didn't work.

The problem is I added "Host:jboss.local.virtual.host" and it gives me: Unable to resolve host "jboss.local.virtual.host": No address associated with hostname.

Was it helpful?

Solution 2

Solved by me:

    final SSLSocketFactory sslFactory = getSSLSocketFactory();
    final Socket socket = sslFactory.createSocket(IP, PORT);

    final int contentLenght = request.renderSafe().

    final PrintWriter pw = new PrintWriter(socket.getOutputStream());
    pw.println(FIRST_HTTP_HEADER);
    pw.println(HOST);
    pw.println(CONTENT_TYPE);
    pw.println(CONTENT_LENGTH + ":" + contentLenght);
    pw.println("");
    pw.println(request);
    pw.flush();

Only this solution worked for me.

OTHER TIPS

You could try something like this:

1. Define your client:

HttpParams params = new BasicHttpParams();

// For instance, you could set timeout
HttpConnectionParams.setConnectionTimeout(params, 10000);

HttpClient client = new DefaultHttpClient(params);

2. Create the request:

HttpGet request = new HttpGet("your URL");

3. Execute the request:

HttpResponse response = client.execute(request);

// And now, for example, get the status code and the server response body
int status = httpResponse.getStatusLine().getStatusCode();
HttpEntity body = response.getEntity();

Notice this is an example about a GET request. You could use any other Http method.

Here, you can see another example: http://www.androidsnippets.com/executing-a-http-post-request-with-httpclient

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top