【问题标题】:Retrieving HTML form data in POST http header in Python在 Python 的 POST http 标头中检索 HTML 表单数据
【发布时间】:2013-02-07 20:57:47
【问题描述】:

我有以下 HTML 代码。它创建一个表单,一旦我点击提交,就会向服务器发送一个请求。

 <html>
 <body bgcolor = black text= white>
 <FORM method="post" action="/processData.py">
 <P>
 <LABEL for="firstname">First name: </LABEL>
 <INPUT type="text" id="firstname"><BR>

 <LABEL for="lastname">Last name: </LABEL>
 <INPUT type="text" id="lastname"><BR>

 <LABEL for="email">email: </LABEL>
 <INPUT type="text" id="email"><BR>

 <INPUT type="radio" name="sex" value="Male"> Male<BR>
 <INPUT type="radio" name="sex" value="Female"> Female<BR>

 <INPUT type="submit" value="Send"> <INPUT type="reset">
 </P>
 </FORM>
 </body>
 </html>

当我点击提交时,我的网络服务器上收到了一个 POST http 请求。但不是获取所有字段的值。我只得到单选按钮的值。这是我得到的标题:

POST /Test.html HTTP/1.1
Host: 127.0.0.1:22222
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25
Content-Length: 10
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*//*;q=0.8
Origin: http://127.0.0.1:22222
Content-Type: application/x-www-form-urlencoded
Referer: http://127.0.0.1:22222/File.html
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive

sex=Female

我希望数据显示在标题之后。为什么不显示?

【问题讨论】:

    标签: python html http


    【解决方案1】:

    我认为您需要为所有输入定义 name 属性

    现在只有收音机有名字

    <INPUT type="radio" name="sex" value="Male"> Male<BR>
    <INPUT type="radio" name="sex" value="Female"> Female<BR>
    

    给出名称属性:

    <LABEL for="lastname">Last name: </LABEL>
    <INPUT type="text" id="lastname" name="lastname"><BR>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-01
      • 2015-07-03
      • 2011-09-06
      • 1970-01-01
      • 1970-01-01
      • 2011-08-02
      • 2021-10-24
      • 2015-11-19
      相关资源
      最近更新 更多