Solved!
This gave me the correct hint: Request to j_security_check return 408 error only with right paramters
Querying the url /j_security_check is where to send the request to in order to retrieve cookies and the website status code.
I'm trying to send a HTTP 'get' request to the website of the company I work for in order to verify that it is up and running. It is hosted on an "Apache Tomcat" server (7.0.34). However, the response code / message always times out.
When using the browser, the site clearly works (but it is slow). I need to be able to programmatically get the response code 200.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HTTPRequest
{
URL url;
HttpURLConnection connection;
public HTTPRequest() throws IOException
{
url = new URL("http://www.google.com");
connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(15000);
connection.setReadTimeout(15000);
System.out.println("Response code: " + connection.getResponseCode());
System.out
.println("Response message: " + connection.getResponseMessage());
}
public static void main(String[] args) throws IOException
{
new HTTPRequest();
}
}
Output Google:
Response code: 200
Response message: OK
Output company site:
Response code: 408
Response message: Request Timeout
I used the methods setConnectTimeout() and setReadTimeout() but they both have no effect, the result is printed just as fast as before: HttpURLConnection setConnectTimeout() has no effect