Let’s say we have an HTML form for sending data to the php/webserver server
<!DOCTYPE html>
<html>
<head>
<title>Form</title>
</head>
<body>
<form action="https://website.com/form.php" method="POST" accept-charset="utf-8">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit" value="Send">
</form>
</body>
</html>
When a user sends a request to a server, how does the server know in what encoding the client sent the data? I analyzed the request headers and realized that despite using accept-charset="utf-8"
, the charset
attribute was not added to the Content-Type
header.
In general, I am interested in the following questions:
- How does the server know the encoding of the data sent?
- Is there a default encoding for HTTP request data?
- Can a
charset
be specified in theContent-Type
header of an HTTP request? If so, how do I addcharset
?