我在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