数组究竟是如何进行 urlencode 编码的?
许多语言允许通过 url 传递一组值。由于各种原因,我需要直接手动构建 url。值数组如何进行 urlencode 编码?
Many languages allow one to pass an array of values through the url. I need to , for various reasons, directly construct the url by hand. How is an array of values urlencoded?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来像 MIME-Type 形式的内容:
application/x-www-form-urlencoded
。用于 POST。要为 GET 执行此操作,您必须在 URL 后面附加一个
?
,其余部分几乎相同。在评论中,mdma 指出,URL 不能包含用于空格字符的+
。请改用%20
。因此,值数组:
库中通常有一些功能可以为您执行 URL 编码(第 1 点)。第二点很容易实现,方法是循环数组、构建字符串、附加索引、
=
、URL 编码值,如果不是最后一个条目,则添加&
。It looks like the content in the form of MIME-Type:
application/x-www-form-urlencoded
.Which is used for the POST. To do it for the GET, you'll have to append a
?
after your URL, and the rest is almost equal. In the comments, mdma states, that the URL may not contain a+
for a space character. Instead use%20
.So an array of values:
Often there is some functionality in libraries that will do the URL encoding for you (point 1). Point two is easily implementable by looping over your array, building the string, appending the index,
=
, the URL encoded value and when it's not the last entry an&
.