我在Java中发出需要SSL证书和私钥组合的POST请求。我已经看过Java密钥,并使用两个命令创建从.KEY和.cert文件既是.jks文件:Java - 使用证书和私钥生成HTTP POST请求
winpty openssl pkcs12 -export -in certificate.crt -inkey privatekey.key -out abc.p12
keytool -importkeystore -srckeystore abc.p12 -srcstoretype PKCS12 -destkeystore abc.jks -deststoretype JKS
但这个失败,403的异常请求。实际上,我想在java中执行以下Javascript函数:
function cardBalance(intent, session, response) {
var options = {
key: fs.readFileSync('privatekey.key'),
cert: fs.readFileSync('certificate.crt'),
host: "blah.blah.blah.com',
path: '/abc/def/ghi/jkl/mno/pqr/creditcardsummary',
method: 'POST',
headers: {
'Authorization': 'Bearer ' + session.user.accessToken,
'Content-Type': 'application/json',
'Version': '1.1.0',
'zId': '1234',
'aId': '123456789',
'bId': 'bId',
'AppName': 'AppName'
}
};
var postData = JSON.stringify({
'acctnum': '00002600452999820832'
});
console.log(options);
var req = https.request(options, function (res) {
console.log('Request Credit Card Balance');
var data = '';
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function() {
data = JSON.parse(data);
console.log(data);
if (data.CreditCardSummary.status === 'SUCCESS') {
var balance = data.balance;
console.log('Balance: ' + balance);
var speechOutput = 'The current balance is $' + balance;
response.tell(speechOutput);
} else {
response.tell('There was a problem getting your card balance.');
}
});
});
req.on('error', function (e) {
console.log('An Error Occurred when calling the Gateway. ' + e);
response.tell(e);
});
req.write(postData);
req.end();
}
向我们展示一个[mcve],一个具体的错误,以及到目前为止您尝试解决的问题。 –
对不起,没有提供足够的细节。还是要谢谢你的帮助 – jtmickde