[英]how to put a body in a get request?
i gonna send a get request, but i need to send with a body, when i use a postman it works well, but if i use axios, it dosent't works.我要发送一个 get 请求,但我需要发送一个正文,当我使用邮递员时,它运行良好,但如果我使用 axios,则它不起作用。
i use axios in javascript and i use postman我在 javascript 中使用 axios,我使用 postman
var settings = {
"url": "http://127.0.0.1:5000/user/history",
"method": "GET",
"processData": false,
"data": "{"summoner":"몽디로 맞아봐"}"
}
$.ajax(settings).done(function (response) {
console.log(response);
});
axios({
url: 'http://127.0.0.1:5000/user/history',
method: 'get',
data: {
'summoner': '몽디로 맞아봐'
}
});
i expect this code works我希望这段代码有效
ES6: ES6:
import axios from 'axios'; let requestHeader, data; data = { 'summoner': '몽디로 맞아봐' } requestHeader = { 'Content-Type':'application/json' } axios.get('http://127.0.0.1:5000/user/history', { params: data, headers: requestHeader }).then((response) => { console.log(response) })
In HTTP specification, sending GET request with body is ok, you can try it with http module in nodejs.在 HTTP 规范中,发送带有 body 的 GET 请求是可以的,您可以在 nodejs 中使用 http 模块尝试它。
But, axios' implementation whichs bases on XHR will remove all the body of GET request before sending.但是,基于 XHR 的 axios 实现将在发送之前删除 GET 请求的所有主体。
Fetch api do the same thing like axios. Fetch api 和 axios 做同样的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.