How to make a api call using axios to a cgi file

Viewed 145

I'm using axios to make a call to an API that I created, I'm passing two values email and password. My api always retrn empty because my cgi file is not getting anything for email & password from axios or postmate(using to test the api call), but if in the browser I load the full url it works fine.

Any ideas what am I doing wrong.

Part of the form

initialValues = {{email: '', password:''}}
onSubmit = {(values, {setSubmitting}) => {
    if (values.email == '' || values.password == '') {     
        handleMessage("Please fill all the fieldss");
        setSubmitting(false);
    } else {
        handleMessage("");
        setSubmitting(true);
        handleLogin(values, setSubmitting);
    }
}}

AXIOS CALL

const handleLogin = (data, setSubmitting) => {
        
    const url = 'https://mydesitte.or/register.cgi'; 
    axios
        .post(url, data)
        .then((response) => {
            // const result = response.data;
            // const {message, status, data} = result;
            alert(data.email);
            setSubmitting(false);
        }).catch(error => {
            alert(error);
            setSubmitting(false);
        });  
}

CGI file

my $cgi          = new CGI;  
 
# This is always empty when I do the call from the my react native app or postmate
my $email = $cgi->param('email');
my $password  = $cgi->param('password');

If I go to this url on the browser https://mysite.or/register.cgi?email=email&password=pass work fine

1 Answers

You need to pass POST data as an object:

axios.post(url, {
    email: email,
    password: pass
})
Related