E
E
EVOSandru62018-09-21 15:01:21
AJAX
EVOSandru6, 2018-09-21 15:01:21

How to make the Content-Type header not fly away in axios post request?

Good afternoon!

axios
                    .post('http://api.domen/controller/action', json_obj, {
                        headers: {
                            'Authorization': 'Bearer asdasdasdadsasd=',
                            'Content-Type': null
                        }
                    })
                    .then(response => {
                    })
                    .catch(error => console.log(error));

This: Didn't help, flies away: Content-Type: null
'Content-Type': null

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Sokolov, 2018-09-21
@EVOSandru6

At the entry point to the application (main.js or index.js), set the settings for axios, for example:
In general, it's better to look at the documentation, because. perhaps this header is required for the HTTP protocol or sent automatically by the browser.
UPD: Here are different options https://github.com/axios/axios/issues/382

axios.defaults.headers.common = {};
axios.defaults.headers.common.accept = ‘application/json’;

or
transformRequest: [(data, headers) => {
    delete headers.common['Content-Type']
    return data
}]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question