你的HttpParams用于创建HttpEntity HttpEntityEnclosedRequestBase对象上设置,然后你可以有一个列表返回使用下面的代码
final HttpPost httpPost = new HttpPost("http://...");
final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("a_param", username));
params.add(new BasicNameValuePair("a_second_param", password));
// add the parameters to the httpPost
HttpEntity entity;
try
{
entity = new UrlEncodedFormEntity(params);
httpPost.setEntity(entity);
}
catch (final UnsupportedEncodingException e)
{
// this should never happen.
throw new IllegalStateException(e);
}
HttpEntity httpEntity = httpPost.getEntity();
try
{
List<NameValuePair> parameters = new ArrayList<NameValuePair>(URLEncodedUtils.parse(httpEntity));
}
catch (IOException e)
{
}
我做了一个类似的事情,只是为了从URI获取参数(这是一个Groovy片段,在Java中也是如此): 'def uri = new URI(“https://www.yahoo.com?foo =“bar”) List parameters = new ArrayList (URLEncodedUtils.parse(uri,“UTF-8”)); parameters.each {参数 - > println parameter.name +“:”+ parameter.value}' 这是一种体面的方式来解构请求的参数,而不会搞乱HttpParams对象,除非你准确的知道你想要什么。 –
2012-11-01 19:16:21