Junior — Middle
What Content-Type types are permissible when sending HTTP requests?
sobes.tech AI
Answer from AI
When sending HTTP requests, the Content-Type header specifies the type of the request body content. The most common types:
application/json— for transmitting data in JSON format.application/x-www-form-urlencoded— for transmitting form data in URL encoding.multipart/form-data— for transmitting files and form data.text/plain— plain text.application/xmlortext/xml— for XML data.
The choice depends on the data format the server expects. For example, REST APIs most often use application/json.
Example of setting Content-Type in Java using HttpURLConnection:
connection.setRequestProperty("Content-Type", "application/json");