2

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());
    }
1
  • This might be a simple firewall issue. Check whether you can get to my.url.com/test/stock.php from the device's browser. Commented Apr 30, 2012 at 17:18

1 Answer 1

4

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>
Sign up to request clarification or add additional context in comments.

1 Comment

i had wifi issue on device. i wasn't checking if wifi was on or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.