Php 我执行POST请求,服务器接收并记录GET请求

Php 我执行POST请求,服务器接收并记录GET请求,php,android,post,http-post,Php,Android,Post,Http Post,在Android应用程序中,Java执行POST请求,由php处理 这在本地工作时效果很好,apache会记录一篇帖子: 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

在Android应用程序中,Java执行POST请求,由php处理

这在本地工作时效果很好,apache会记录一篇帖子:

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)"
执行POST的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());
    }
}
private void-HttpPost(字符串php,ArrayList-nameValuePairs){
试一试{
HttpClient HttpClient=新的DefaultHttpClient();
String host=com.android.taggies.logiuser.getContext().getResources().getString(R.String.host);
HttpPost HttpPost=新的HttpPost(主机+php);
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
HttpResponse response=httpclient.execute(httppost);
HttpEntity=response.getEntity();
is=entity.getContent();
}捕获(例外e){
e(“Log_标记”,“http连接错误”+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();
?>

我的POST请求也有问题,无法将图像上载到我的外部LAMP服务器。这确实帮助了我:

它是一个包含几个GET和POST方法的类。尝试使用以下方法:

public static HttpData post(String sUrl, Hashtable<String, String> ht) throws Exception {
            String key;
            StringBuffer data = new StringBuffer();
            Enumeration<String> keys = ht.keys();
            while (keys.hasMoreElements()) {
                    key = keys.nextElement();
                    data.append(URLEncoder.encode(key, "UTF-8"));
                    data.append("=");
                    data.append(URLEncoder.encode(ht.get(key), "UTF-8"));
                    data.append("&amp;");
            }
            return HttpRequest.post(sUrl, data.toString());
    }
publicstatichttpdata-post(stringsurl,Hashtable-ht)引发异常{
字符串键;
StringBuffer数据=新的StringBuffer();
枚举键=ht.keys();
while(keys.hasMoreElements()){
key=keys.nextElement();
data.append(URLEncoder.encode(键,“UTF-8”);
数据。追加(“=”);
data.append(URLEncoder.encode(ht.get(key),“UTF-8”);
数据。追加(“&;”;
}
返回HttpRequest.post(sUrl,data.toString());
}

我想你需要一些外部课程。请检查链接。

如果我没记错的话,这是android的跨域问题,它无法向外部服务器发送POST请求,只能获取。我可能弄错了。