Send body in method GET axios

时间:2019-04-08 12:58:24

标签: javascript

How i send body in method GET, but i'm not getting.

i try, but don't working

const res = await axios({
    method: 'get',
    url: `${this.state.url}Docto/Imagens`,
    headers: {
        Authorization: `Bearer ${Token}`,
        "Content-Type": "application/json"
    },
    processData: false,
    data: { Id: 4075 },
    body: { Id: 4075 }
})

In Postman, the request normally worked enter image description here

I know the correct would be to pass the parameter via querystring on get, but the back end did this way.

1 个答案:

答案 0 :(得分:0)

GET request does not have a body, use a query string instead. With axios I usually use npm package qs which is used also in axios docs:

Config:

    {
       ...
       // `paramsSerializer` is an optional function in charge of serializing `params`
      // (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/)
      paramsSerializer: function (params) {
        return Qs.stringify(params, {arrayFormat: 'brackets'})
      },
      ....
    }