Firefox和Chrome POST期间与CR + LF替换LF [英] Firefox and Chrome replacing LF with CR+LF during POST
问题描述
为什么Firefox和Chrome取代POST过程中与CR + LF一个LF?
我写了下面作为一个测试:
< HTML和GT;
< HEAD>
&所述; SCRIPT SRC =https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js>&下; /脚本>
<脚本类型=文/ JavaScript的>
功能lftest()
{
VAR换行符=之前;
换行+ = String.fromChar code(10); //换行
换行+ =后面;
$(#场)VAL(换行)。
$(#formthing)提交()。
}
< / SCRIPT>
< /头><身体GT;
<表ID =formthing方法=邮报行动=http://someurl.com/resource>
<输入类型=隐藏ID =场值=NAME =行/>
< A HREF =#的onclick =lftest()>发< / A>
< /表及GT;
< /身体GT;
< / HTML>
开发工具网络选项卡显示POST数据:
%0D%0Aafter前
原来,这与在X WWW的形式urlen codeD编码类型的事情。据规范:
非字母数字字符由%HH,百分号,代之以
两个十六进制数重新presenting字符的ASCII code。
订单符重新psented为CR LF对$ P $(即'0D%0A%')
块引用>Why does Firefox and Chrome replace the LF character with CR+LF during POST?
I wrote the following as a test:
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script> <script type="text/javascript"> function lftest() { var linefeed = "before"; linefeed += String.fromCharCode(10); //linefeed linefeed += "after"; $("#field").val(linefeed); $("#formthing").submit(); } </script> </head> <body> <form id="formthing" method="post" action="http://someurl.com/resource"> <input type="hidden" id="field" value="" name="line" /> <a href="#" onclick="lftest()">send</a> </form> </body> </html>
The developer tools network tab shows the POST data:
before%0D%0Aafter
解决方案Turns out that this has to do with the x-www-form-urlencoded encoding type. According to the spec:
Non-alphanumeric characters are replaced by '%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., '%0D%0A').
这篇关于Firefox和Chrome POST期间与CR + LF替换LF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!