Node uses request to forward the request, post/json format, and the back end cannot receive the request and directly reports an error.

  node.js, question
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);
            }

        }
    });

}

The node log keeps reporting error and error code 400, but the backend has not actually received my request, and I don’t know why

One case is that the backend uses a proxy server. Has your request host been modified to the hostname of the interface address? If it is still your browser address, it may be intercepted by the proxy server.

The second is when post requests, the server will judge whether the header’s content-length is consistent with your data’s length. If not, it will be directly broken, because this is a wrong request.