开发者

Android- UnknownHostException stumper

i have been trying to call a PHP script with the android system. i am using Eclipse helio and everything else i have written works fine on it - not much yet. so i block copied this code and it does not work: i have no warnings or errors and i can debug and step through it, but it always comes back with

"E log_tag : Error in http connection java.net.UnknownHostException: www.X.com"

here is the code:

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);  
    nameValuePairs.add(new BasicNameValuePair("Lat","19.80"));
    nameValuePairs.add(new BasicNameValuePair("Lon","13.22"));
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://www.X.com/new/getAllPeopleBornAfter.php");
    try{
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        InputStream is = entity.getContent();
        Log.i("postData", response.getStatusLine().toString());
    }
    catch(Exception e)
    {
        Log.e("log_tag", "Error in http connection "+e.toString());
    }       

and the PHP which runs fine if i go there with a browser:

mysql_con开发者_如何学编程nect("mysql27.x.com","name","PW");
mysql_select_db("dbname");
$q = mysql_query("SELECT * FROM people");
while ($e = mysql_fetch_assoc($q))  $output[] = $e;
mysql_close();
echo (json_encode($output));

?>

if you guys want me to run anything in a different format or any more info - please let me know - i cant find any thing more than just unknownhostexception


  1. Can you access www.X.com from the emulator/phone?
  2. Do you have the INTERNET permission?


Did you remember to put:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

into your manifest file?


Are you behind a proxy network? Should you be setting the proxy ip address and port number? I'm no good with php. But I get this error when I try to connect to the internet through java programs. The solution works good for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜