I have a java application trying to post to a php file on an IIS server and when I execute the post I get the java.net UnknownHostException. I have the set in the androidmanifet.xml right above the application element. Can somebody please help?
If your server is on a subnet, make sure you're including the full hostname in your HttpPost, e.g. barney.awesome.domain.com and not simply barney
I figured it out. Turns out the emulator that was started through eclipse would not connect to the internet. Had to manually start it up. Does anyone know why the emulator through eclipse does not connect to the internet?
Related
I've tried running an app that fetches JSON data from the internet through an HTTP Request object, It showed
java.net.UnknownHostException: Unable to resolve host “api.github.com”: No address associated with hostname
as the Exception for every trial. Later I checked the internet connectivity in the AVD by running a browser. I wasn't able to access any site.
Is there any settings that I'll have to change in the AVD Manager so that I can access the in the Internet through the Virtual Device.
Help me out, Thanks in Advance.
If that is your exact error, I see what's wrong just from that.
Android API's, unlike any modern browser, requires explicit declaration of http or https.
You have to make sure the URL contains either of those protocols which you either can do by adding it into the URL manually, or adding this code before you create the volley request:
if(!url.startsWith("http://") && !url.startsWith("https://")){
url = "http://" + url;
}
You could replace it with HTTPS, but not all sites have https, so it's a generally good idea to default it to HTTP to not get errors from that. If you supply https but there's no HTTPS certificate, the website will most likely refuse the connection.
In my case , I received such error when the Emulator could not connect to the internet.
(Try browsing the internet using the Emulator to test its internet connection. suggested in https://teamtreehouse.com/community/unknownhostexception-unable-to-resolve-host-apidarkskynet-no-address-associated-with-hostname)
I'm doing a project to connect Android with local Tomcat server. But now I'm facing a problem for about 1 week. Who can help me..Thanks very much!
I use the newest android API and Tomcat 7.0. When I start Tomcat server. I can access the Tomcat homepage through emulator browser with url:(http://10.0.2.2:8080). But when I use HttpUrlConnection in the code. I cannot get the successful connection. I also use httpurlconnection to access www.google.com and www.android.com. I cannot connect them either.I use HttpURLConnection.HTTP_OK to see whether it make a successful connection. I also see the Connected is false for HttpURLConnection instance I make.
By the way I also add the internet access permission for it in AndroidManifest.xml before tag.
Thank you very much! Help me. It's emergency.
I recently had this problem. As mentioned above, (on Windows) start cmd, and use ipconfig to find the PC's IP address. Also, due to my Eclipse/Tomcat configuration I needed to have my Eclipse project name in the URL. The URL I used was like this: http://192.168.1.2/myEclipseProject/ServletName
Also, you may need to add the port to the ip address, if your Tomcat still has the default configuration: 192.168.1.2:8080
I have a python REST API server running on my laptop. I am trying to write a rest client in Android (using Eclipse ADT etc) to contact it using Apache's client (org.apache.http.client) libraries.
The code is really simple, and basically does the following -
HttpGet httpget = new HttpGet(new URI("http://10.0.2.2:8000/user?username=tim"));
HttpResponse response = httpclient.execute(httpget);
However at execute, it exceptions out with a time out exception. I cannot hit the URL even from the browser in the emulator.
Details of the exception
org.apache.http.conn.ConnectTimeoutException: Connect to /10.0.2.2:8000 timed out
However, I tried using the cREST client on Chrome on my laptop, and I am able to query the REST server fine.
Is it possible the machine is not on your network? Ie - it is on the other side of a router, on the internet somewhere? Because addresses starting "10." are reserved as private addresses and not routable.
See http://en.wikipedia.org/wiki/Private_network for more info
I had the same issue and here's how I figured out the cause:
Quit you emulator. Start your local server. In the browser, you should be able to access "http://localhost:8000/user?username=tim" and get some response. If you get a timeout, your server is likely not running. In my case, my python server had a break-point set and it was stuck there. Once I let it run, I was able to see responses on the browser and subsequently in the emulator (using 10.0.2.2).
I am implementing twitter for android. When i am requesting for Request Token. It throws me this error:
04-27 11:25:01.163: DEBUG/ERROR=(3467): Host is unresolved: api.twitter.com:80
Before it was working fine. Suddenly it started giving this error.
Thanks in advance, aby
That sounds like a DNS lookup error. If you have a network tool suite installed that allows nameserver lookups (GTech Net Tools is one of these, and it's free) try entering api.twitter.com to see if your emulator can resolve the IP address.
One other thing to note is that you should be using HTTPS to call the OAuth resources at Twitter. From the :80 on your request, you can tell that whatever called oauth/request_token used plain old HTTP. All network communication involved in negotiating your OAuth tokens should be secured.
I understand that we can use HTTP as well(If your system lacks a security cert). You can tell the library to use HTTP call by adding the following line before the initializing the Twitter connection object.
System.setProperty("twitter4j.http.useSSL","false");
I had the same problem and after many tries it seems that the problem was in the emulator.. when trying the program on 1.5 it worked. However, it didn't work on 2.1. I opened the native emulator browser on 2.1 and it failed to load the google page (probably the emulator got an internet connection problem)
I am developing an app in Android, and the emulator is not connecting to my localhost.
I have researched the issue and found some ideas but nothing seems to be working.
Below is the code i have been using:,
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://10.0.2.2/YES_BUTTON.php");
httpclient.execute(httpPost);
I have also tried a connection using "http://10.0.2.2:3128/YES_BUTTON.php";
The code would run a php file, but nothing happens, I have also checked the server access log and no connection was ever made with the Apache server from the emulator.
This is my first time building an app, and was wondering if there was something I haven't done, do I need to map the emulator port with the 3128 port on Apache, disable the firewall? I am developing the app on a laptop,with the Apache Server on the laptop also, so everything is being done on the same machine. Is there anything I havent done that needs to be done?
I bet you forgot to add the INTERNET permission :)
INTERNET