爲什麼Firefox和Chrome在POST期間用CR + LF替換LF字符?Firefox和Chrome在POST期間用CR + LF替換LF
我寫了下面的測試:
<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>
開發工具網絡選項卡顯示POST數據:
before%0D%0Aafter
但表單輸入值在POST期間被編碼。 %0A不是LF協議的HTTP協議 – pepsi
@pepsi這是一個很好的觀點。儘管如此,就我所知,這些瀏覽器總是*做到了這一點,而且我發現的唯一解釋就是協議。 (當然,你的觀察結果讓人很懷疑:-) – Pointy