0

I use fetch to send data to webservice. How can I do this with axios ?

 fetch('url', {
        method: 'POST',
        headers: new Headers({
                     'Accept': 'application/json',
                    'Content-Type': 'application/json', // <-- Specifying the Content-Type
            }),
             body: JSON.stringify(object)
        })
rnn
  • 2,393
  • 3
  • 21
  • 39

1 Answers1

2

Here is some code that is close to what you want.

 axios({
    method: 'post',
    url: 'myurl',
    data: bodyFormData,
    config: { headers: {'Content-Type': 'application/json' }}
    })
    .then(function (response) {
        //handle success
        console.log(response);
    })
    .catch(function (response) {
        //handle error
        console.log(response);
    });

Alternately, you can set you configuration then use axois.post(). This axios cheatsheat may help you as well.

Sam Mullinix
  • 196
  • 1
  • 10
  • what should I give to data ? object ? – rnn Jul 08 '19 at 14:14
  • Yes that is where you data will go. You can also do axios.post(URL, Object); Check [this](https://stackoverflow.com/questions/45578844/how-to-set-header-and-options-in-axios) link for more info. – Sam Mullinix Jul 08 '19 at 14:27
  • @hakan did this answer your question? – Sam Mullinix Jul 11 '19 at 15:23
  • Oh thx bro yes it is ! . I have one more question can u help me about that please ? https://stackoverflow.com/questions/56991655/how-to-send-base64-code-to-webservice-webservice – rnn Jul 11 '19 at 15:26