在HttpClient中的PostMethod中传递arrayList多图

时间:2015-03-05 21:39:47

标签: java arraylist apache-httpclient-4.x multimap apache-commons-httpclient

我有以下代码:

public static void postHttpStream(ArrayListMultimap<String, String> fcmbuildProperties){
                HttpClient client = new HttpClient();
                PostMethod method = new PostMethod("http://requestb.in/y2d30py2");
                try {
                  int statusCode = client.executeMethod(method);
                  String test = fcmbuildProperties.ge
                  method.setRequestBody(fcmbuildProperties);
                  byte[] responseBody = method.getResponseBody();
                  System.out.println(new String(responseBody));
                } catch (Exception e) {
                  System.err.println("Fatal error: " + e.getMessage());
                  e.printStackTrace();
                } finally {
                  method.releaseConnection();
                }
     }

fcmBuildProperties是一个arrayList多重映射,但看起来setRequestBody只接受一个名称值对。问题是在我的arrayList中,一个键可以有多个值。他们是一个简单的方法来传递它作为有效载荷?

1 个答案:

答案 0 :(得分:0)

关于在初始化身体之前序列化属性的内容是什么?

// serialize your properties
String body = ...
method.setRequestBody(body);