繁体   English   中英

Spring Android:如何使用百分比编码将urlencoded表单发布到服务器

[英]Spring Android: how to post form urlencoded to server using percent-encoding

我如何配置RestTemplate(Springframework)以使用百分比编码而不是字符编码进行编码,例如我将以下参数发布到服务器:

client_id = xxx

client_secret = xxx

grant_type = client_credentials

scope = public_read注册

但是在发布时,spring将其发送为:

client_id = xxx&client_secret = xxx&grant_type = client_credentials&scope = public_read + registration

我希望它像这样:

client_id = xxx&client_secret = xxx&grant_type = client_credentials&scope = public_read%20registration

它将空格转换为+,我希望它是%20

谢谢

您可以使用此:

字符串formated_urlString = URLEncoder.encode(unformated_url_string,“ utf-8”)。replace(“ +”,“%20”)。

另请参见URLEncoder无法翻译空格字符

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM