我正在尝试将一些php代码转换为nodejs / javascript
我是使用nodejs和Axios的菜鸟,我不知道自己是否做对了。但我认为它可以与以下代码一起使用
exports.getCheckOutId = async (amount ) => {
const data = {
'authentication.userId' : userId,
'authentication.password' : password,
'authentication.entityId' : entityId,
'amount' : amount,
'paymentType' : paymentType,
'currency' : currency
};
return await axios({
method: 'post',
url: host + path,
data: data,
rejectUnauthorized: false
});
};
当我尝试检查发生了什么情况
const response = getCheckOutId(5).then(result => console.log("after then: ", result) );
console.log(response);
我刚得到
Promise { <pending> }
我看不到回复
我尝试了一个不带有rejectUnauthorized:false的情况,以防ssl是问题。 我也尝试过这种方法,但是我看不到任何控制台日志或错误。
axios.post(url, data, axiosConfig).
then((response) => {
console.log('accessed successfully');
return response;
}).catch((err) => {
console.log("AXIOS ERROR: ", err);
return null;
})
答案 0 :(得分:1)
您没有发现错误,因此也没有向您显示错误所在。试试这个:
exports.getCheckOutId = async amount => {
const data = {
'authentication.userId': userId,
'authentication.password': password,
'authentication.entityId': entityId,
amount: amount,
paymentType: paymentType,
currency: currency,
};
try {
const result = await axios({
method: 'post',
url: host + path,
data,
rejectUnauthorized: false,
});
console.log('result: ', result);
return result;
} catch (e) {
console.error(e);
}
};