Reputation: 60
hi guys i'm trying to connect to my web page on server. i have checked my code there are no mistakes in it and it works on the emulator but i get force close on the actual device and the in log it says unknown host exception. did any one else run into this.
Error in http connectionjava.net.UnknownHostException: my.url.com
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://my.url.com/test/stock.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
Upvotes: 2
Views: 732
Reputation: 54780
First, do a quick sanity check and make sure you can hit that URL from your device using the browser. If not, then you have a wifi/connection issue on your device.
If you have no issue hitting the URL from the browser, make sure you have the correct permission set in your Android manifest:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Upvotes: 4