Node uses request to forward requests in post/json format. If the request is not received by the backend, an error will be reported directly.

reqData({
        url: url,
        body: req.query.data, //json
        timeout: timeout,
        method: method,
        headers: {
            "content-type": "application/json; charset=utf-8"
        }
    }, function(err, data) {

        if(!err) {
            res.write(JSON.stringify(data));
            res.flush();
            res.end();
        } else {
            var result = {
                flag:1,
                msg:""
            }
            res.end(JSON.stringify(result));
        }
    });
    
    function reqData(options, callback) {
    logger.info("request options:", options);

    request(options, function(err, response, body) {
        if(err) {

            logger.error("Error:" + err.message +"\n" + err.stack + "\n", "request & response body:", options, body);
            callback(err);
        } else {
            try {
                callback(null, JSON.parse(body));
            } catch(err) {
                logger.error("Error:" + err.message +"\n" + err.stack + "\n", "request & response body:", options, body);
                callback(err);
            }

        }
    });

}
    
    
    

node log keeps reporting error, and error code 400, but the backend actually didn"t receive my request. I don"t know where the reason is

.
Jan.13,2022

one case is that the backend uses a proxy server. Does your request host change to the hostname? of the interface address? If it is still your browser address, it may be blocked by the proxy server.

the second is that when a post request is made, the server will determine whether the content-length of header is the same as that of your data. If not, it will be cut off directly, because this is an incorrect request

.

400 is usually caused by incorrect parameters. First check the content-type, and then check the request method and parameter passing method


in nodejs, the parameters of the get request and post request are obtained differently. The get request can take the parameters directly, but the post request cannot do so. You need to wait for the end event to get the complete parameters.
you need to eliminate the problem of locating interferers. First, try whether the simple get request is normal, which is used to verify whether the request and response logic of node is correct


troubleshooting step:
1, make sure you can access the server normally. You can query the access result locally through the ping command;
2, if it can be accessed normally, print out all the parameters, and access them through postman and other API debugging tools to see if there are any exceptions;
3, if postman access is normal, check the code to see which one is inconsistent with the settings of postman; if postman access is abnormal, try to modify content-type to other values and verify them one by one.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7c2d59-2aa1e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7c2d59-2aa1e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?