开发者

Basic HTTP forms posting

I have a page with nothing on it but this form:

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

After entering values into "usernamed" and "password", when the form is submitted via the submit butt开发者_如何学Con, I get this HTTP header:

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

My question is, why aren't the "username" and "password" form field values being posted in the content of the HTTP post?


When sending form data, the names are retrieved from the name attribute, not from the id. Try this:

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

Or, if you need the id for something else:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜