我必须在 nodejs 中模拟 curl 请求:
curl -k POST https://example.com/ --cert mycert.pem:password
我已经写了一些代码,但它的工作方式与此不同:
request.post(
{
'url': 'https://example.com/',
'agentOptions': {
'pfx': fs.readFileSync('./mycert.pem'),
'passphrase': 'password',
}
}
)
获取“错误:标签错误”。但它适用于 curl 。 如果有任何帮助,我将不胜感激。
最佳答案
以下是否有效?
const exec = require('child-process-promise').exec;
const cmd = 'curl -k POST https://example.com/ --cert mycert.pem:password';
exec(cmd).then(res => console.log(res.stdout)).catch(console.error);
关于javascript - 在nodejs中模拟curl请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52191190/