In my IIS i have created Web Api and it's Project Url is http://localhost:54444.
I am albe to connect to this Url from my browser in Windows8, however I am not able to do so in my android emulator browser via http://10.0.2.2:54444
.
My android browser is able to connect to google.com.
I am also trying to make an client in Eclipse using http://loopj.com/android-async-http/ library:
Log.v("bopzy_debug", "Testing HTTP Connectivity");
System.out.println("123");
AsyncHttpClient client = new AsyncHttpClient();
client.get("http://10.0.2.2:54444/api/values/",
// client.get("http://google.pl",
new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
Log.v("bopzy_debug", response);
}
@Override
public void onFailure(Throwable error, String content)
{
System.out.println("onFailure");
System.out.println(content);
Log.w("bopzy_debug", error);
}
@Override
public void onFinish() {
System.out.println("onfinish:");
Log.v("bopzy_debug", "Finished..");
}
});
}
The LogCat info I'm getting:
07-18 09:18:17.471: V/bopzy_debug(1354): Testing HTTP Connectivity
07-18 09:18:17.471: I/System.out(1354): 123
07-18 09:18:17.621: I/System.out(1354): onFailure
07-18 09:18:17.644: I/System.out(1354): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
07-18 09:18:17.644: I/System.out(1354): <HTML><HEAD><TITLE>Bad Request</TITLE>
07-18 09:18:17.644: I/System.out(1354): <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
07-18 09:18:17.644: I/System.out(1354): <BODY><h2>Bad Request - Invalid Hostname</h2>
07-18 09:18:17.652: I/System.out(1354): <hr><p>HTTP Error 400. The request hostname is invalid.</p>
07-18 09:18:17.652: I/System.out(1354): </BODY></HTML>
07-18 09:18:17.652: W/bopzy_debug(1354): org.apache.http.client.HttpResponseException: Bad Request
07-18 09:18:17.652: W/bopzy_debug(1354): at com.loopj.android.http.AsyncHttpResponseHandler.sendResponseMessage(AsyncHttpResponseHandler.java:235)
07-18 09:18:17.652: W/bopzy_debug(1354): at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:79)
07-18 09:18:17.652: W/bopzy_debug(1354): at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:95)
07-18 09:18:17.652: W/bopzy_debug(1354): at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:57)
07-18 09:18:17.652: W/bopzy_debug(1354): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
07-18 09:18:17.652: W/bopzy_debug(1354): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
07-18 09:18:17.652: W/bopzy_debug(1354): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
07-18 09:18:17.652: W/bopzy_debug(1354): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
07-18 09:18:17.652: W/bopzy_debug(1354): at java.lang.Thread.run(Thread.java:856)
07-18 09:18:17.682: I/System.out(1354): onfinish:
07-18 09:18:17.682: V/bopzy_debug(1354): Finished..
I have added:
<uses-permission android:name="android.permission.INTERNET" />
to AndroidManifest.xml file.
Any suggestion will be appreciated.