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

查看:93
本文介绍了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

user%5Blogin%5D=username&user%5Bpassword%5D=123456

我很好奇%5B%5D用户登录键中的含义.

I'm curious what the %5B and %5D means in the key user login.

如何解码这些数据?

推荐答案

根据 here 上的这个答案:str='foo%20%5B12%5D'foo [12] 进行编码:

As per this answer over here: str='foo%20%5B12%5D' encodes foo [12]:

%20 is space
%22 is quotes
%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天全站免登陆