How to mimic an HTML form submission in a POST request?

前提是你 提交于 2019-11-28 17:34:11
Martin

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.


Here's what the request could look like for your form:

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=

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!