Is there a Java method that encodes a collection of parameters as a URL query component?

后端 未结 5 892
逝去的感伤
逝去的感伤 2021-01-12 12:56

Is there a widely-used Java library that does something like what dojo.objectToQuery() does? E.g. (assuming the use of HttpCore\'s HttpParams object, but any key-value mappi

5条回答
  •  隐瞒了意图╮
    2021-01-12 13:52

    Why reinvent the wheel? Apache HttpClient has URLEncodedUtils:

       List params = Arrays.asList(new BasicNameValuePair("\\%^ &=@#:", "\\%^ &=@#:"));
       String query = URLEncodedUtils.format(params, "UTF-8");
    

提交回复
热议问题