I'm catching a device event, and based on info coming from it it I need to do a login. If the login is verified, I want to move to the next page of my application.
I tried doing it with HttpURLConnection
but it doesn't actually execute the servlet.
This is the genetic code I'm using:
public static String getResponseFromUrl(String url) throws Exception {
URL website = new URL(url);
HttpURLConnection connection = (HttpURLConnection)website.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
connection.setUseCaches(false);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String response = "";
String inputLine;
while ((inputLine = in.readLine()) != null)
response += inputLine;
in.close();
return response.toString();
}
I also tried
InputStream responseInputStream = connection.getInputStream();
but with the same result. The doGet
method is not being called, and obviously the app doesn't move to the next page.
I'm pretty sure this can be done by catching the event inside the JSP
page but I was hoping there's an easier solution.
EDIT: When submitting the same URL in the browser it all works. The doGet is called and the app moves to the next page.