I'm trying to make a GET request to a ASP.NET Web API from Android. The API should return a JSON object with some users. When calling the API from the browser everything works fine, but when attempting to call from the Androind application nothing happens. I've looked into Fiddler and no requests are sent.
This is the code I use to make the call:
class GetData extends AsyncTask<String, String, String>{
@Override
protected String doInBackground(String... params){
HttpClient client = new DefaultHttpClient();
HttpResponse response;
try{
HttpGet get = new HttpGet("http://10.0.2.2:38216/api/user");
response = client.execute(get);
if(response != null){
InputStream inStream = response.getEntity().getContent();
String message = convertToString(inStream);
return message;
}
}
catch(Exception exp){
Log.d("Error message!", exp.toString());
}
return null;
}
}
Any ideas or hints on what I'm doing wrong would be appreciated!
localhost
of the development machine running that emulator? If yes, did LogCat show an exception and stack trace? Also, are you sure that you are executing this task? – CommonsWare Jul 16 '13 at 12:24client.execute(get)
is called but response comes back with nothing useful and Fiddler doesn't show any call to the Web API. – Cosmin Ionascu Jul 16 '13 at 12:2738216
? Or did you set up Fiddler as a proxy in your Web browser, and port38216
is the Web app itself? – CommonsWare Jul 16 '13 at 12:36