如果您希望 POST 的整个原始正文成为字符串化数组(仅此而已),我相信您应该使用 StringEntity 而不是 UrlEncodedFormEntity。
所以这:
String s = "asdf"; // replace this with your JSON string
StringEntity stringEntity = new StringEntity(s);
httpPost.setEntity(stringEntity);
我不熟悉 PHP,但从概念上讲,在接收端你会做类似 json.parse(request.full_body) 的事情。请注意,这(request.full_body 或等效项)与获取 POST 表单的单个值(如 request['input_field1'] )的常见模式非常不同。
但是,阅读您的问题,我并不完全确定这种 full_body 方法是您想要的。在我看来,您想通过表单变量“数组”访问数据,正如您在此处指出的那样:
$_POST['array']=array("key"=>"value","key2"=>"value2");
Note that you are not working with the entire POST body here, rather instead you are fetching the value of a single form variable called 'array' (I think, I don't really know PHP). If this is the case, then you should use NameValuePairs like something below:
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("array", yourJSONArrayAsString));
This will post the array as a value associated with the form variable 'array' I believe.