POST请求中的%5B和%5D代表什么? [英] What does %5B and %5D in POST requests stand for?

查看:9210
本文介绍了POST请求中的%5B和%5D代表什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个Java类来登录某个网站。在POST请求中发送的数据是

I'm trying to write a Java class to log in to a certain website. The data sent in the POST request to log in is

用户%5Blogin%5D = uesrname& user%5Bpassword%5D = 123456

我很好奇%5B %5D 表示密钥用户登录

如何对这些数据进行编码?

How do I encode these data?

推荐答案

根据此处的回答: str ='foo%20%5B12%5D'编码 foo [12]

%20 is space
%5B is '['
and %5D is ']'

这称为百分比编码并用于编码url参数值中的特殊字符。

This is called percent encoding and is used in encoding special characters in the url parameter values.

编辑顺便说一下我正在阅读 https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/encodeURI#Description ,我刚想到为什么这么多人进行相同的搜索。请参阅页面底部的注释:

EDIT By the way as I was reading https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/encodeURI#Description, it just occurred to me why so many people make the same search. See the note on the bottom of the page:


另请注意,如果有人希望关注更近期的 RFC3986
用于URL,保留方括号(用于IPv6),因此在形成时不会编码
可能是URL的一部分(例如
主机),以下内容可能有所帮助。

Also note that if one wishes to follow the more recent RFC3986 for URL's, making square brackets reserved (for IPv6) and thus not encoded when forming something which could be part of a URL (such as a host), the following may help.



function fixedEncodeURI (str) {
    return encodeURI(str).replace(/%5B/g, '[').replace(/%5D/g, ']');
}

希望这可以帮助人们在遇到这个问题时理清他们的问题。

Hopefully this will help people sort out their problems when they stumble upon this question.

这篇关于POST请求中的%5B和%5D代表什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆