Socket hang up read ECONNRESET

recently, using the http module of nodejs, you can request the past when using the original service address. The server has the request content, and the client also has the returned data, all of which are correct and have no problem.

but when using the address of the local host: 127.0.0.1, localhost, or native IP, it will report an error. The error message is

.

socket hang up
read ECONNRESET

here is my code for using the http module:

function send_req_http(serverUrl, port, req_client_json, send_res_handler){
    var options = {
        host: serverUrl,
        port: port,
        path: "/",
        method: "POST",
        json: true,
        headers: {
            "Content-Type": "application/json",
            "Content-Length": req_client_json.length
        }
    }
    const post_req = http.request(options, send_res_handler)
    post_req.on("error", (err)=>{
        alert(err);
    })
    post_req.write(req_client_json);
    post_req.end();
}

after using the local host as the server, in the log of the server, the server receives the request sent by the client, queries the database according to the request, and returns the corresponding content (all of which are correct). However, the client keeps displaying these two errors.

again, it is completely feasible to use this method with the original service address. I just changed the IP address.

In addition, I have seen a lot of solutions to similar problems in Baidu and github, among which the addition of agent:false in options is the most popular, and it does not work to try. In addition, it is not useful to convert
"Content-Length": req_client_json.length
in headers to
" Content-Length": Buffer.byteLength (req_client_json)
, and some add security protocols, even related to the version.

in short, kneeling and begging everyone for help, I am not very clear about the principle of this error (I just know that there is a problem with the connection, of course, there is also some Baidu), and I am even more puzzled about the solution to the problem and why it is solved in this way. Black Pangyuan would like to thank you all!

Mar.23,2021
Menu