Home > Software engineering >  Axios post form urlencoded requests application/x-www-form-urlencoded
Axios post form urlencoded requests application/x-www-form-urlencoded

Time:12-15

I'm trying to make a requests post with axios, sending that postdata from a checkbox and submit button, but I don't know how to do this correctly with axios, I would appreciate your help `

const URI = "https://www.guadeloupe.gouv.fr/booking/create/12828/0"
    const data = "condition=on&nextButton=Effectuer une demande de rendez-vous"
    const headers = {
    'Content-Type':           'application/x-www-form-urlencoded',
    'User-Agent':             'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
    'Accept-Encoding':        'gzip, deflate, br',
    'Origin':                 'https://www.guadeloupe.gouv.fr'
    }
    
    const resp = await axios.post(URI,data,headers)

with insomnia = INSONMIA POST REQUEST SCREEN SHUT

CHECKBOX = PHOTO CHECKBOX SUBMIT

CodePudding user response:

I can't test with real REST server but I can suggest this code.

It's base on your image and code.

const resp = await axios.post(URI,
            new URLSearchParams({
                'condition': 'condition',
                'nextButton': 'Effectuer une demande de rendez vous' 
            }),
            {
                headers:
                {
                    'Content-Type': 'application/x-www-form-urlencoded'
                }
            })
  • Related