node.js Error: connect ECONNREFUSED; response from server

前端 未结 6 1003
再見小時候
再見小時候 2020-12-09 03:52

I have a problem with this little program:

var http = require(\"http\");
var request = http.request({
    hostname:          


        
6条回答
  •  无人及你
    2020-12-09 04:30

    Please use [::1] instead of localhost, and make sure that the port is correct, and put the port inside the link.

    const request = require('request');
    
       let json = {
            "id": id,
            "filename": filename
        };
        let options = {
            uri: "http://[::1]:8000" + constants.PATH_TO_API,
            // port:443,
            method: 'POST',
            json: json
        };
        request(options, function (error, response, body) {
            if (error) {
                console.error("httpRequests : error " + error);
            }
            if (response) {
                let statusCode = response.status_code;
                if (callback) {
                    callback(body);
                }
            }
        });
    

提交回复
热议问题