This article mainly introduces node. http. response. the writeHead method is described in this article. response. writeHead method description, syntax, receiving parameters, use instances and implementation source code. For more information, see
Method description:
Sends a response header to the requested client.
This function can be called at most once in a request. If this function is not called, a response header is automatically generated.
Syntax:
The Code is as follows:
Response. writeHead (statusCode, [reasonPhrase], [headers])
Receiving parameters:
StatusCode HTTP status code, such as 200 (successful request) and 404 (not found.
ReasonPhrase
Headers is similar to an object associated with an array, indicating each attribute of the response header.
Example:
The Code is as follows:
Var body = 'Hello world ';
Response. writeHead (200 ,{
'Content-length': body. Length,
'Content-type': 'text/plain'
});