且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在POST请求中模仿HTML表单提交?

更新时间:2022-02-18 05:49:08

POST请求包含多个标题和一个请求机构。当您提交表单时,浏览器 URL编码所有表单字段的名称和值,然后将它们放入在此格式的请求正文中:

A POST request consists of a number of headers and a request body. When you submit a form, the browser URL encodes names and values of all form fields and then puts them in the request body in this format:

fieldname1=fieldvalue1&fieldname2=fieldvalue2

即请求正文看起来像一个典型的查询字符串。

I.e. the request body looks like a typical query string.

以下是表单的请求:

POST /bugreport.php HTTP/1.1
Host: www.example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: [size of the request body]

logfile=blabla&configfile=more+blabla&usercomment=hello&useremail=






为了确保您的程序符合浏览器的功能,您可以使用Firefox发布表单,然后使用 Firebug 的网络面板检查请求标题和正文。


To make sure your program matches what a browser would do, you can post the form with Firefox and then inspect the request headers and body using Firebug's net panel.