Note: Don't get confused by the term Form Data in the screen shot. The things to notice here are the Content-Type header which says application/x-www-form-urlencoded, the query string and the form fields are transferred to the server in the format as discussed above. Try creating an HTML file with the above code and see how it's submitted in the dev tools. They share the same format discussed above. Username=sidthesloth&password=slothsecretĪlso, notice that we have some query parameters passed in the action URL, /urlencoded?firstname=sid&lastname=sloth.ĭon't the URL encoded body and the query parameters passed in the action URL look awfully similar? It's because they are similar. ![]() Each (name, value) pair is separated from one another by a & (ampersand) sign, and for each (name, value) pair, the name is separated from the value by an = (equals) sign, like say, Basically, a long string of (name, value) pairs are created. But how is the body formatted? It is URL encoded. Here, you can see that the form is submitted to the server using a POST request, this means that it has a body. ![]() Take the following form,Įnter fullscreen mode Exit fullscreen mode Now, let us look at each form type with an example to understand them better.Īs the name suggests, the data that is submitted using this type of form is URL endcoded. Text/plain - A new form type introduced in HTML5, that as the name suggests, simply sends the data without any encoding This type of form is used when the user wants to upload files Multipart/form-data - Represents a Multipart form. The encoding type of a form is determined by the attribute enctype. ![]() So thought it might be a good thing to share what I learned and hence the post. While doing that I ended up learning some fundamentals of how HTML forms work. The other day I was trying to write a REST endpoint in Go, which uploads the contents of a form submitted in a browser to another REST endpoint, in other words,įorm in Browser -> My GO Rest API -> Another REST API
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |