Java 如何在android的http post中发送数组?
在android中,当我发布http帖子时,我使用以下代码创建url参数: 我想在http请求中发送一个字符串和两个字符串列表。但是在php代码中,我无法验证是否所有参数都存在。在下面的代码中,我希望php if语句为true,但它为false。有人知道这里出了什么问题吗 我在这里看到了答案 您可以将参数的名称放在方括号中,然后在php中它将是一个数组 谢谢Java 如何在android的http post中发送数组?,java,php,android,http,Java,Php,Android,Http,在android中,当我发布http帖子时,我使用以下代码创建url参数: 我想在http请求中发送一个字符串和两个字符串列表。但是在php代码中,我无法验证是否所有参数都存在。在下面的代码中,我希望php if语句为true,但它为false。有人知道这里出了什么问题吗 我在这里看到了答案 您可以将参数的名称放在方括号中,然后在php中它将是一个数组 谢谢 List<NameValuePair> urlValues = new ArrayList<NameValueP
List<NameValuePair> urlValues = new ArrayList<NameValuePair>();
urlValues.add(new BasicNameValuePair("id", ID));
for(MyLocation item : THlocationList) {
urlValues.add(new BasicNameValuePair("THlocationList[]", item.ID));
urlValues.add(new BasicNameValuePair("THlocationList[]", item.location));
urlValues.add(new BasicNameValuePair("THlocationList[]", item.date));
}
for(String item : deletionList ) {
urlValues.add(new BasicNameValuePair("deletionList[]", item));
}
在你的Android中,你会得到什么样的响应?在php代码中,我将其设置为如果if语句为false,我会打印一些字符串,这就是我得到的字符串,所以我知道if语句正在变为false。
public static Pair<String,Integer> GetHTTPResponse(String url, List<NameValuePair> urlparameters) {
String result = null;
int responseCode = 0;
try {
HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(urlparameters));
HttpResponse response = client.execute(httppost);
responseCode = response.getStatusLine().getStatusCode();
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
result = rd.readLine().trim();
}
catch (Exception e) {
responseCode = 0;
}
return new Pair<String, Integer>(result, responseCode);
}
if (isset($_POST['id']) && isset($_POST['THlocationList']) && isset($_POST['deletionList'])) {
...
}