我对 android 上的 http POST 请求有疑问。
主要目的是发送一个“字典中的字典”,在 API 中它看起来像
array('make_event'=>array(event_name'=>'测试事件','event_start'=>'2012-12-01 10:00:00','event_end'=>'2012-12-02 10:00 :00','host'=>10001001000,'is_global'=>0,'place_name'=>'Vasya\'s Appartments','place_id'=>666666666,'lat'=>49.00003,'long'=> 54.30001,'受邀'=>'135,1002541,21231,32321'))
这是我对请求的实现
List<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
Bundle bndl = new Bundle();
bndl.putString("event_name","New Test Event");
bndl.putString("event_start", "2013-01-04 10:12:09");
bndl.putString("event_end", "2013-02-04 12:12:09");
bndl.putLong("host", 100003017925182L);
bndl.putInt("is_global", 1);
bndl.putString("place_name","Some PLace");
bndl.putString("place_id", "42cc7080f964a520e9251fe3");
bndl.putDouble("lat", 37.78573590563453);
bndl.putDouble("long", -122.40610713227913);
bndl.putString("invited","100000879281531");
String tmpStr = bndl.toString();
tmpStr = tmpStr.replace("Bundle", "");
pairs.add(new BasicNameValuePair("make_event", tmpStr));
post.setEntity(new UrlEncodedFormEntity(pairs));
Log.v("My Post", "" + pairs.toString());
//HttpResponce
HttpResponse response = client.execute(post);
我的任务是发送一个 http POST 并接收一个 JSON 响应。
所以我的问题是:我做得还好吗,还是有另一种方法可以通过 http POST 在数组中发送数组?
已解决问题的答案是: Java Android: How to make complex POST requests to API?