cocofcb6
cocofcb6

Reputation: 37

How use 'application/x-www-form-urlencoded' in Get method with axios

when I use Postman tool to test my request GET, everything is working when I check 'application/x-www-form-urlencoded' in Body settings

But when I use Axios, I feel that my settings are not taken into account! Because I have the following error "the user does not exist"

axios({
        method: 'get',
        url: `${baseURL}/api/collect/getSante`,
        params: {
            lastName: 'value'
        },
        headers: {
            'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
        }
})

I expect json response but I have "the user does not exist"

Upvotes: 1

Views: 4907

Answers (1)

Cap Barracudas
Cap Barracudas

Reputation: 2505

Maybe you could try using URLSearchParams for application/x-www-form-urlencoded. F.e. :

const params = new URLSearchParams();
params.append('param1', 'value1');
params.append('param2', 'value2');
axios.post('/foo', params);

Source: https://github.com/axios/axios#using-applicationx-www-form-urlencoded-format

Upvotes: 2

Related Questions