我一直在尝试用android系统调用PHP脚本。我正在使用Eclipse helio,我编写的其他所有东西都可以正常使用-尚不多。所以我阻止复制此代码,但它不起作用:我没有警告或错误,可以调试并逐步执行它,但始终会返回
“ E log_tag:http连接java.net.UnknownHostException中的错误:www.X.com”
这是代码:
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());
}
和PHP,如果我用浏览器去那里运行良好:
mysql_connect("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));
?>
如果你们希望我以其他格式或任何其他信息运行任何内容-请让我知道-我找不到除unknownhostexception以外的任何东西
最佳答案
您可以从仿真器/电话访问www.X.com吗?
您具有INTERNET权限吗?