Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot send post method in "request" function from Axios instance #723

Closed
alpancs opened this issue Feb 23, 2017 · 7 comments
Closed

cannot send post method in "request" function from Axios instance #723

alpancs opened this issue Feb 23, 2017 · 7 comments

Comments

@alpancs
Copy link
Contributor

alpancs commented Feb 23, 2017

When I try to send POST method using this code:

const axios = require('axios')
let config = {url: 'http://{{hostname}}', method: 'post'}
let instance = axios.create(config)
instance.request()

It send GET method instead of POST.

I think this line https://github.com/mzabriskie/axios/blob/master/lib/core/Axios.js#L37 should be: config = utils.merge(defaults, this.defaults, config);

@chengluyu
Copy link

I've got the same problem. Here is the code.

2017-02-26 6 39 10

The login function uses request module, which worked well. However, the axiosLogin function, which uses axios, always failed. Both of them were applied with same arguments.

I'm not sure whether that line matters.

@alpancs
Copy link
Contributor Author

alpancs commented Feb 27, 2017

I have tested by modifying this line https://github.com/mzabriskie/axios/blob/master/lib/core/Axios.js#L37 into config = utils.merge(defaults, this.defaults, config);. It works, but no permission to push my branch.

@cameronk
Copy link

I also have this issue. It seems to me that instance.request() should use the method defined in options, falling back to GET if necessary.

@mightym
Copy link

mightym commented Mar 23, 2017

I even have this with a normal POST request:

    axios.defaults.headers.common['X-CSRFToken'] = getCookie('csrftoken');
    return axios({
      method: 'post',
      url: url,
      data: {
        link: link
      }
    })
    .then(function (response) {
      console.log(response);
    })
    .catch(function (error) {
      console.log(error);
    });

Its really strange. Chrome/Safari tell me that it is a XHR GET request.

@rubennorte
Copy link
Member

Right, it seems we should move the default method to defaults:

config = utils.merge(defaults, this.defaults, { method: 'get' }, config);

Have you considered creating a PR?

Thanks for reporting.

@humiston
Copy link

humiston commented Feb 6, 2018

I am experiencing this as well. When attempting to use both axios({method: 'post', ...) and axios.post(...), I see in the response that a GET request is being fired. This pretty much makes axios worthless to me.

@emilyemorehouse
Copy link
Member

Fixed in #1342

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants