节点JS中的https POST API调用出现404错误

时间:2019-05-15 04:39:38

标签: node.js https

我正在尝试在Node JS中进行https调用。这是电话:

var options = {
    hostname: "https://example.net",
    path: "/abc/test",
    method : 'POST',
    headers: {
        "Content-Type": "application/x-www-form-urlencoded"
    }
};
const req = https.request(options, (res: any) => {
    res.setEncoding('utf8');
    res.on('data', (chunk: any) => {
        // Some Processing on response
    });
});

req.on('error', (error: any) => {
    console.log("Network Error with the HTTP Call. Error: " + error.message);
});

req.write('resource=rs1&query1=sample1&query2=sample2');
req.end();

因此,我期望对带有附件的正文的该URL:“ https://example.net/abc/test”进行POST调用,但令我惊讶的是,我总是遇到此错误:Network Error with the HTTP Call. Error: getaddrinfo ENOTFOUND https://example.net https://example.net:443

这表示呼叫本身并未接通,尽管从Postman可以打到该连接似乎正在工作。 https调用有什么问题吗?

0 个答案:

没有答案