简体   繁体   中英

Axios post returning 404

I am trying to send a post request with query params using axios (running in node.js), but its responding with 404 if its sent like this

let response = await axios.post(config.API_ENDPOINT, {
        params: {
            q: 'addLead',
            key: config.API_KEY,
            firstName: lead.firstName,
            workPhone: lead.workPhone,
            userName: lead.userName,
            projectName: lead.projectName
        }
    });

however it works if I form the query parameters through string like this (without params object):

let url = config.API_ENDPOINT + `?q=addLead&key=${config.API_KEY}&firstName=${lead.firstName}&workPhone=${lead.workPhone}&userName=${lead.userName}&projectName=${lead.projectName}`;

The former way being neat and secure I guess, I can't figure out what's wrong, help!

In case of a post request, the second parameter is reserved for the body payload, the third parameter is where you sent the params.

let response = await axios.post(config.API_ENDPOINT, null, {
        params: {
            q: 'addLead',
            key: config.API_KEY,
            firstName: lead.firstName,
            workPhone: lead.workPhone,
            userName: lead.userName,
            projectName: lead.projectName
        }
    });

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