Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用Java模拟$.ajax数组POST请求_Java_Javascript_Php_Ajax - Fatal编程技术网

如何用Java模拟$.ajax数组POST请求

如何用Java模拟$.ajax数组POST请求,java,javascript,php,ajax,Java,Javascript,Php,Ajax,我试图用java程序模拟ajax post请求 模拟工作正常,但如果我发布一个数组,它将作为字符串返回 我用的是番石榴: Map<String, String> data = new HashMap<String, String>(); data.put(URLEncoder.encode("affected_ids[]", "UTF-8"), URLEncoder.encode(Joiner.on(":").join(arrIds), "UTF-8")); data.

我试图用java程序模拟ajax post请求

模拟工作正常,但如果我发布一个数组,它将作为字符串返回

我用的是番石榴:

Map<String, String> data = new HashMap<String, String>();

data.put(URLEncoder.encode("affected_ids[]", "UTF-8"), URLEncoder.encode(Joiner.on(":").join(arrIds), "UTF-8"));
data.put("select_all", "true");

String d = Joiner.on("&").withKeyValueSeparator("=").join(data);
并将其转换为PHP字符串:

array(1) {
  [0]=>
  string(139) "504728:121741:121742:124908:316787:560950:560955:560957:560958:560960:516653:504729:504732:504741:504748:504749:552317:552320:552321:552324"
}
我尝试了不同的分隔符:“,”和“”,但运气不好


正确的格式是什么?

如果希望PHP自动将数据识别为数组,则必须发送多个同名参数,每个参数以
[]
结尾

例如:

foo[]=1&foo[]=2
将在PHP中作为
$\u GET['foo']
访问,返回数组
数组(1,2)

更多信息可在和中找到

foo[]=1&foo[]=2