【发布时间】:2011-02-16 01:57:21
【问题描述】:
我一直在尝试使用 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 之外,我找不到任何东西
【问题讨论】: