Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html post方式提交数据编码问题 #9

Open
Alexis374 opened this issue May 16, 2016 · 0 comments
Open

html post方式提交数据编码问题 #9

Alexis374 opened this issue May 16, 2016 · 0 comments
Labels

Comments

@Alexis374
Copy link
Owner

最近项目中遇到了这方面的问题,算是比较基础的知识吧。
前端向服务端发起请求,服务端返回一长串数据,数据是类似a=12&b=34c=56这样的(当然真实的数据远远比这个长且复杂),前端需要分隔出来每个数据然后再组成表单,post到另一个server上。

之前理解的post表单其实是把每个表单的name和value用=&符号连接成字符串发送到server,那是否可以偷懒地传递,即name为a,然后值为12&b=34&c=56...这样的形式联结起来呢?

结果当然是不可以的。

构造一个html,内容如下

<html>
    <head>
        <meta charset="utf-8">
    </head>
    <body>
        <form action="http://baidu.com" method="POST">
            <input type="text" name="a">
            <input type="text" name="b">
            <input type="submit" value="submit">
        </form>

         <form action="http://baidu.com" method="POST">
            <input type="text" name="a">
            <input type="submit" value="submit">
        </form>
    </body>

</html>

通过抓包分析,第一个表单中分别填入12,34,http的body为a=12&b=34,若把=12&b=34填入第二个表单,则http的body为a=12%26b%3D34,可知&被转义为 %26,=被转义为 %3D。这种编码方式被成为 百分号编码,或url编码,用于编码url和表单数据。其实从表单的默认enctype=application/x-www-form-urlencoded 也可以看出用的是这种编码。虽然以前知道表单的enctype,但是看来还是需要融会贯通啊

@Alexis374 Alexis374 added the html label May 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant