是否有一种Java方法将参数集合编码为URL查询组件?

栏目: Java · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/1405731/is-there-a-java-method-that-encodes-a-collection-of-parameters-as-a-url-query-co
有没有广泛使用的 Java 库可以像 dojo.objectToQuery() 那样做什么?例如. (假设使用HttpCore的 HttpParams

对象,但任何键值映射都会这样做):

HttpParams params = new BasicHttpParams()
    .setParameter("foo", "bar")
    .setParameter("thud", "grunt");
UnknownLibrary.toQueryString(params);

应该产生“foo = bar& thud = grunt”.

我知道写起来并不难,但似乎应该已经写好了.我找不到它.

为什么重新发明轮子? Apache HttpClient 有URLEncodedUtils:
List<BasicNameValuePair> params = Arrays.asList(new BasicNameValuePair("\\%^ &=@#:", "\\%^ &=@#:"));
   String query = URLEncodedUtils.format(params, "UTF-8");

翻译自:https://stackoverflow.com/questions/1405731/is-there-a-java-method-that-encodes-a-collection-of-parameters-as-a-url-query-co


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Beginning Google Maps API 3

Beginning Google Maps API 3

Gabriel Svennerberg / Apress / 2010-07-27 / $39.99

This book is about the next generation of the Google Maps API. It will provide the reader with the skills and knowledge necessary to incorporate Google Maps v3 on web pages in both desktop and mobile ......一起来看看 《Beginning Google Maps API 3》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换