在nodejs中模拟curl请求
Emulate curl request in nodejs
我必须在 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',
}
}
)
获取“错误:标签错误”。但它适用于卷曲。
如果有任何帮助,我将不胜感激。
以下是否有效?
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);
所以,这是解决方案:
request.post(
{
'url': 'https://example.com/',
'key': {
'cert': fs.readFileSync('./mycert.pem'),
'key': fs.readFileSync('./mycert.pem'),
'passphrase': 'password',
}
}
)
还在想,如何使用"pfx"选项...
我必须在 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',
}
}
)
获取“错误:标签错误”。但它适用于卷曲。 如果有任何帮助,我将不胜感激。
以下是否有效?
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);
所以,这是解决方案:
request.post(
{
'url': 'https://example.com/',
'key': {
'cert': fs.readFileSync('./mycert.pem'),
'key': fs.readFileSync('./mycert.pem'),
'passphrase': 'password',
}
}
)
还在想,如何使用"pfx"选项...