是否有一种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


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

查看所有标签

猜你喜欢:

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

The Zen of CSS Design

The Zen of CSS Design

Dave Shea、Molly E. Holzschlag / Peachpit Press / 2005-2-27 / USD 44.99

Proving once and for all that standards-compliant design does not equal dull design, this inspiring tome uses examples from the landmark CSS Zen Garden site as the foundation for discussions on how to......一起来看看 《The Zen of CSS Design》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具