我想将NameValuePairs添加到调用php脚本(查询数据库)的HttpPost中。
以下是我尝试的内容:
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("w", "(id='1a')"));
HttpPost httpPost = new HttpPost("http://www.mysite.tv/getList.php");
UrlEncodedFormEntity requestEntity = new UrlEncodedFormEntity(nameValuePairs);
httpPost.addHeader(requestEntity.getContentType());
httpPost.setEntity(requestEntity);
HttpResponse response = httpClient.execute(httpPost);
我希望只获取id = 1a的元素,但脚本会返回所有元素。如果我这样称呼php:
HttpPost httpPost = new HttpPost("http://www.mysite.tv/getList.php?w=(id='1a')");
它完美无缺。
设置NameValueParis时我做错了什么?有任何想法吗? 提前致谢