I have an Android application which makes calls to a java server application deployed on a Apache server located on my laptop. When testing the application at home, all the calls to the server are successful.
If however, I connect to a different WiFi (in a cafe' for instance), the calls from the application (from the Android client app) are failing without any errors.
Making the requests to the server directly from the Browser works fine.
Android code for making the requests:
class LoginRequestTask extends AsyncTask<String, String, String> {
/*
* Metoda doInBackground() ruleaza pe thread-ul de fundal, in aceasta
* medoda executandu-se request-ul la server pentru logare.
*/
@Override
protected String doInBackground(String... uri) {
String output = null;
try {
String loginUrl = Globals.LoginServletUrl
+ "?operation=login&emailAddress="
+ mTxtEmail.getText() + "&password="
+ mTxtPassword.getText();
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(loginUrl);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
output = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return output;
}
/*
* Metoda onPostExecute() este apelata pe thread-ul UI după ce se
* termină thread-ul de fundal. Este nevoie ca parametrul rezultat de la
* metoda doInBackground(), verificandu-se daca s-a efectuat cu succes
* logarea.
*/
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// Get response
if (result != null && result.equals("true")) {
PrefUtils
.saveToPrefs(LoginActivity.this,
PrefUtils.SESSION_EMAIL, mTxtEmail.getText()
.toString());
Intent i = new Intent(getApplicationContext(), HomeScreen.class);
startActivity(i);
Toast.makeText(getApplicationContext(), "Logare cu succes.",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
"Logarea nu a fost realizata.", Toast.LENGTH_SHORT)
.show();
}
}
}
The last line executed is:
HttpResponse httpResponse = httpClient.execute(httpGet);
After that, nothing happens. No exceptions are raised and the onPostExecute method is not fired.
This is the URL: http://172.20.10.2:8080/Learn2LearnServer/LoginServlet?operation=login&emailAddress=myEmailAddress&password=myPassword
The Internet permission is set in my Android application and of course, the phone has a working network connection when trying.
Any ideas as to what is going on?
Thanks.