Home  >  Article  >  Web Front-end  >  Instructions for using the http.response.writeHead method in node.js_node.js

Instructions for using the http.response.writeHead method in node.js_node.js

WBOY
WBOYOriginal
2016-05-16 16:27:201795browse

Method description:

Send response headers to the requesting client.

This function can only be called once in a request. If not called, a response header will be automatically generated.

Grammar:

Copy code The code is as follows:

response.writeHead(statusCode, [reasonPhrase], [headers])

Receive parameters:

statusCode HTTP status code, such as 200 (request successful), 404 (not found), etc.

reasonPhrase

headers An object similar to an associative array, representing each attribute of the response header

Example:

Copy code The code is as follows:

var body = 'hello world';
response.writeHead(200, {
'Content-Length': body.length,
'Content-Type': 'text/plain'
});
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn