How does content-type work in java?

Asked

Viewed 576 times

2

I saw a video of a guy wearing the

connection.setRequestProperty("content-type", "aplication/x-www-urlencoded");

But I don’t understand how it works, especially the "aplication/x-www-urlencoded".

  • You are setting properties in the HTTP upload header. In this case, you are saying that your content is MIME-like application/x-www-urlencoded. If you want a friendlier mime, we have the text/plain

1 answer

3


Content-Type is an HTTP Header that identifies which data structure will be sent/received from the server, and is language independent.

In this case: Content-Type: application/x-www-urlencoded means that the structure of the sent/received data is a key string query=value separated by &.

Ex:

nome=John&sobrenome=Doe

Another example: Content-Type: application/json means that data will be sent/received following the JSON structure:

{ "nome": "John", "sobrenome": "Doe"}

More in: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.