如何将java对象传递给HTTP Post参数

时间:2013-02-01 11:40:40

标签: java http-post

我想使用java.net.*将java对象传递给HTTP POST参数? Object包含多个参数。

1 个答案:

答案 0 :(得分:1)

尝试

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(REQUEST_URL);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
//put here in nameValuePairs request parameters

UrlEncodedFormEntity form;
form = new UrlEncodedFormEntity(nameValuePairs, "UTF-8");
form.setContentEncoding(HTTP.UTF_8);
httppost.setEntity(form);

HttpResponse response = httpclient.execute(httppost);