Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 16:27:20
Original
1807 people have browsed it

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'
});
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template