嗨,我正在使用苹果酱进行 API 调用。我想将请求正文添加到请求中。我将正文添加为最后一个代码,但它不起作用。我从 apisauce 创建 authSauace,如下所示。
import { create } from "apisauce";
import { AUTHORIZATION } from "../constants/commonStrings";
export const authSauce = create({ baseURL: process.env.REACT_APP_AUTH_BASE, });
export const setHeadersForAllInstances = (token) => { authSauce.setHeader(AUTHORIZATION, `Bearer ${token}`);};
然后我想添加有效载荷如下
authSauce
.get(`/api/query`, null, {
payload: {}
}, {
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}
)
.then((response) => {
if (response.data) {
console.log(response.data);
}
})