2010-11-06 65 views
0

我有什麼就可以了,但這種形式的頁面:基本HTTP形式發佈

<form method="post" action="/sign-in"> 
    <input type="text" id="username" /> 
    <input type="password" id="password" /> 
    <input type="submit" /> 
</form> 

輸入值,「usernamed」和「密碼」,當表單通過提交按鈕提交,我得到後此HTTP標頭:

POST http://localhost:12339/sign-in HTTP/1.1 
Host: localhost:12339 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12)... 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-us,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 115 
Connection: keep-alive 
Referer: http://localhost:12339/ 
Cookie: Authorization=test 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 0 

我的問題是,爲什麼不是「用戶名」和「密碼」表單字段值被張貼在HTTP發佈的內容?

回答

3

發送表單數據時,將從name屬性中檢索名稱,而不是從id中檢索名稱。試試這個:

<form method="post" action="/sign-in"> 
    <input type="text" name="username" /> 
    <input type="password" name="password" /> 
    <input type="submit" /> 
</form> 

或者,如果你需要的ID爲別的東西:

<form method="post" action="/sign-in"> 
    <input type="text" id="username" name="username" /> 
    <input type="password" id="password" name="password" /> 
    <input type="submit" /> 
</form>