简体   繁体   中英

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.

i use axios in javascript and i use 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:

 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.

But, axios' implementation whichs bases on XHR will remove all the body of GET request before sending.

Fetch api do the same thing like axios.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM