2

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

Eddie
  • 26,593
  • 6
  • 36
  • 58
sema0710
  • 25
  • 5

2 Answers2

3

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)
})
Israt Jahan Simu
  • 1,040
  • 13
  • 7
0

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.

thelonglqd
  • 1,805
  • 16
  • 28