Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between content-type and enctype

Tags:

html

forms

gwt

For HTML forms. I am confused, I'm trying to set enctype='application/octet-stream' but the server receives the request with content-type ='application/x-www-form-urlencoded' (the default value).

like image 214
Mina F. Beshay Avatar asked Sep 09 '12 14:09

Mina F. Beshay


People also ask

What is an Enctype?

Definition and Usage The enctype attribute specifies how form-data should be encoded before sending it to the server. The form-data is encoded to "application/x-www-form-urlencoded" by default.

What does Enctype =' multipart form-data mean?

enctype='multipart/form-data' means that no characters will be encoded. that is why this type is used while uploading files to server. So multipart/form-data is used when a form requires binary data, like the contents of a file, to be uploaded. Follow this answer to receive notifications.

Why is the Enctype attribute required for file uploads?

Multipart form data: The ENCTYPE attribute of <form> tag specifies the method of encoding for the form data. It is one of the two ways of encoding the HTML form. It is specifically used when file uploading is required in HTML form. It sends the form data to server in multiple parts because of large size of file.

What is default Enctype?

Default is:"application/x-www-form-urlencoded", assuming my source is correct.


1 Answers

The enctype attribute specifies the content type (in HTTP terms, as indicated in Content-Type header) used by the browser when it submits the form data to server.

However, the spec defines only two content types in this context, application/x-www-form-urlencoded (the default) and multipart/form-data, and adds: “Behavior for other content types is unspecified.” What happens in practice is that browsers silently ignore enctype attributes with other values, using the default. You can see this if you e.g. inspect the document in Firebug: inspecting the form element, the DOM pane contains the property enctype—with the default value. It is common in web browsers to be silent about errors in markup.

The type application/octet-stream would not be very useful in this context, since if the browser sent such information, it would be effectively saying “this is lump of binary data of unknown (or unspecified) structure”.

like image 163
Jukka K. Korpela Avatar answered Sep 22 '22 12:09

Jukka K. Korpela