response.writeHead and response.end in NodeJs

后端 未结 5 1598
予麋鹿
予麋鹿 2020-12-25 10:59
var https = require(\'https\');
var fs = require(\'fs\');

var options = {
  key: fs.readFileSync(\'test/fixtures/keys/agent2-key.pem\'),
  cert: fs.readFileSync(\'t         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-25 11:32

    In your code, the writeHead() is called to write the header of the response, that the application will serve to the client. The end() method both sends the content of the response to the client and signals to the server that the response (header and content) has been sent completely. If you are still going to send anything else, you should call write() method of res response object instead.

    The options JSON object is a modifier that you may use, to override the default behaviour of the createServer() method. In your code's case:
    + key: Private key to use for SSL (default is null)
    + cert: Public x509 certificate to use (default is null)

    You can find more in this section of the Node.js API doc about the response.writeHead() method.
    You can find more in this section of the Node.js API doc about the https.createServer() method.

提交回复
热议问题