HTTP Request Body for Form Values

HTTP Request Header

HTTP clients and servers largely depend on the “Content-Type” header to determine how to parse the request/response body. Common values for the “Content-Type” header are

  • application/json
  • application/atom+xml
  • application/pdf
  • application/octet-stream
  • application/x-www-form-urlencoded

and request/response body should be processed as JSON, XML, PDF, Raw Stream, or Form Data respectively.

How is Form Data Sent?

99.99% of forms in your web applications will be url-encoded and sent in the request body instead of the request URL for obvious reasons.

Parse Form Data with ParseForm()

func (r *Request) ParseForm() error
For all requests, ParseForm parses the raw query from the URL and updates r.Form.

For POST, PUT, and PATCH requests, it also reads the request body, parses it as
a form, and puts the results into both r.PostForm and r.Form. Request body 
parameters take precedence over URL query string values in r.Form.

If the request Body's size has not already been limited by MaxBytesReader,
the size is capped at 10MB.

For other HTTP methods, or when the Content-Type is not 
application/x-www-form-urlencoded, the request Body is not read, and r.PostForm
is initialized to a non-nil, empty value.

URL query parameters are also read in the r.Form map object.


Written with StackEdit.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: