【发布时间】:2022-11-27 17:39:02
【问题描述】:
我尝试使用我的发布请求通过配置发送我的令牌值,但它没有出现在请求标头中最终给我 500 错误 在这里,是以下代码:
export const moneyTransfer = (id, account, amount) => async ( dispatch, getState) => {
try {
dispatch({
type: MONEY_TRANSFER_REQUEST,
});
const {
userLogin: { userInfo },
} = getState();
const config = {
headers: {
Authorization: `Bearer ${userInfo.token}`,
},
};
console.log(config);
const { data } = await axios.post(
`http://localhost:6969/v1/api/transferToAccountByAccountNo?senderAccountNo=${id}&receiverAccountNo=${account}&amount=${amount}`,config );
console.log(data);
dispatch({
type: MONEY_TRANSFER_SUCCESS,
});
} catch (error) {
dispatch({
type: MONEY_TRANSFER_FAIL,
payload:
error.response && error.response.data.message
? error.response.data.message
: error.message,
});
}
};
但我无法在我的 chrome 请求标头中看到它:
POST /v1/api/transferToAccountByAccountNo?senderAccountNo=5&receiverAccountNo=2&amount=123 HTTP/1.1
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-IN,en-US;q=0.9,en;q=0.8
Connection: keep-alive
Content-Length: 103
Content-Type: application/json
Host: localhost:6969
Origin: http://localhost:3000
Referer: http://localhost:3000/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
sec-ch-ua: "Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
【问题讨论】:
-
试试这个 const config = headers: { Authorization:
Bearer ${userInfo.token}, }
标签: reactjs redux axios authorization token