android post request(post [argument]没有值)

时间:2011-11-29 10:57:37

标签: php android post get

我无法从我的Android应用程序发出帖子请求,必须有一些我能看到的愚蠢错误......

HttpPost httppost = new HttpPost("http://www.smth.net/some.php");
try {
    // Add your data
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("pa", "555"));
    nameValuePairs.add(new BasicNameValuePair("pb", "550"));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    // Execute HTTP Post Request
    HttpResponse response = httpclient.execute(httppost);
} catch (Exception e) { 
//no error thrown
}

当我去浏览器并请求时 http://www.smth.net/some.php?ga=15523&ga=34515 只插入了获取值,这是okey。

mysql_query("INSERT INTO t1 (a,b) VALUES (" . $_GET["ga"] . "," . $_GET["gb"] . ")");
mysql_query("INSERT INTO t1 (a,b) VALUES (" . $_POST["pa"] . "," . $_POST["pb"] . ")");

1 个答案:

答案 0 :(得分:0)

试试这个,让我知道会发生什么,

HttpClient httpclient = new DefaultHttpClient();

    HttpPost httppost = new HttpPost("http://www.smth.net/some.php");
    httppost.addHeader("Content-Type", "application/x-www-form-urlencoded");

    HttpPost httppost = new HttpPost("http://www.smth.net/some.php");

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("pa", "555"));
    nameValuePairs.add(new BasicNameValuePair("pb", "550"));

    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));

    // Execute HTTP Post Request

    HttpResponse response = httpclient.execute(httppost);

检查回复,你得到了什么..