Annie
Annie

Reputation: 2587

Pass Array/Object as parameter in Axios React native

I want to pass parameter in POST request in Axios library as :

{
  params : 
  {
            email: email,
            password: password,
  }
}

I have tried :

axios.post(url, 
            { 
                params : {
                    email: '[email protected]',
                    password: 'Password!',
                    sign_in_type: '1',
                    fb_token: '',
                    google_token: ''
                }
            }, 
            {headers: headers}
        )

But nothing works! Please suggest if you have any idea.

Thank you!

Upvotes: 0

Views: 405

Answers (1)

Sarmad Shah
Sarmad Shah

Reputation: 3805

 const getData = async () => {
        const params = {
          params: {
              email: '[email protected]',
              .....
          }
        };
    try {
        const { data } = await axios({
            method: 'post', 
            url: `your url`,
            data: params,
            headers: {
             'token': token
           }
        });
     console.log(data);
    } catch(e) {
     console.log(e);
    }
 }

Upvotes: 1

Related Questions