简体   繁体   中英

How I can set Content-Type in react to application/json

My React code as down below

在此处输入图片说明

and it always turn to text/plain;charset=UTF-8

在此处输入图片说明

I found that cors support just

application/x-www-form-urlencoded
multipart/form-data
text/plain

but I want to send the json to Http req. how I can fix it?

The problem is that you're setting the wrong HTTP header to accept JSON as a response. The header you should set is Accept:

axios.get('my/url', {
    headers: {
        'Content-Type': 'application/json',
         Accept: 'application/json'
    }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM