Axios 不会发送正文参数



当我在背面打印身体参数表时,它们是未定义的。但是当我使用 POSTMAN 发送相同的请求时,它可以工作。我不知道我错过了什么。

export const test = obj => {
const body = qs.stringify({
mode: obj.mode,
partition: obj.partition
});
const config = {
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
};
return dispatch => {
dispatch({ type: "GET_CONSIGNE_BEGIN" });
return axios
.get("http://localhost:8080/Mode-Partition-Consignes", body, config)
.then(result => {
dispatch({ type: "GET_CONSIGNE_SUCCESS", payload: result.data });
})
.catch(err => {
dispatch({ type: "GET_CONSIGNE_FAILURE", err });
});
};
};

对于 axios,通过 GET 发送数据的唯一方法是通过属性参数。

客户端上的示例:

axios.get("/api", {
params: {
foo: "bar"
}
});

服务器上的示例:

router.get("/api", (req, res) => {
const { foo } = req.query;
});

希望对您有所帮助。快乐编码。

最新更新