使用npm请求的POST请求

时间:2019-05-31 09:25:03

标签: node.js http-post

如何使用npm请求模块执行以下操作?

curl -vvvvv -X POST -d "test msg" 'https://app.sms.sender/?destination=12341234' --cacert /loc/to/cert

我尝试这样做:

 let options = {
    url: format(process.env.PATH_URL, number),
    headers: {
        'User-Agent': process.env.USER_AGENT
    },
    agentOptions: {
        cert: fs.readFileSync(process.env.SMS_CERT_PATH),
    },
    body: "test msg"
};

//store url in env
request.post(options, function(error, response, body) {
    ...
});

但是我一直收到cannot read property 'toString' of undefined

0 个答案:

没有答案