1
在Android应用程序中,Java执行POST请求,并使用PHP处理它。我做POST请求,服务器接收并记录GET请求
本地工作时也能正常工作,Apache日志一个POST:
192.168.1.123 - - [29/Mar/2012:15:46:56 +0200] "POST /usuarioLogin.php HTTP/1.1" 200 292 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
当远程工作,Apache日志GET请求,显然没有找到发送的参数。 Apache日志如下:
78.XXX.256.XXX - - [29/Mar/2012:16:20:05 +0200] "GET /usuarioLogin.php HTTP/1.1" 200 267 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
的java的执行邮编:
private void HttpPost(String php, ArrayList<NameValuePair> nameValuePairs) {
try {
HttpClient httpclient = new DefaultHttpClient();
String host = com.android.taggies.LoginUser.getContext().getResources().getString(R.string.host);
HttpPost httppost = new HttpPost(host + 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());
}
}
而且PHP:
<?php
mysql_connect("localhost","root","");
mysql_select_db("dbBaggies");
$q=mysql_query("SELECT count(*) as 'return' FROM users
WHERE name='$_POST[user]' AND password ='$_POST[pass]'");
while($e=mysql_fetch_assoc($q))
{
$output[]=$e;
}
print(json_encode($output));
mysql_close();
?>
如果我记得没错,这是android的跨域问题,它无法对外部服务器执行POST请求,只有GET。我可能会误解。 – Th0rndike 2012-03-29 15:00:21