3
votes

i want to force the content-type to application/json but i have a mode "no-cors" and actually the return for content-type is : text/plain;charset=UTF-8 its the same when i pass the headers so i don't know how do this.

I have already tried to use fetch or Axios, the URL is in HTTP and i work in local so maybe it's the problem? I have tried on Postman, that work great.

     fetch('http://link', {
            method: 'POST',
            credentials: 'include',
            redirect: 'follow',
            mode: 'no-cors',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                "cluster_id" : [],
                "surname" :["albert"],
                "gender" :[],

            }),
        }).then((result) => {
            this.setState({ allClient: result.data }, () => {
                this.setState({ load: true })
                console.log(this.state.allClient)
        })

So, i want to have content type: application/json and not Content-Type: text/plain;charset=UTF-8

1

1 Answers

0
votes

You've mentioned CORS and localhost, but I don't know that your issue is with either of them based on the information provided.

The content-type header specifies the MIME type for the body following the header. For your request, it's the type of the request body. For the response, it's the type for the response body.

You're correctly setting the content type of your request, and telling the server what you're looking for w/ the accept header, but ultimately it's up to the server-side to set the header. If you control the server, you can adjust as needed, but otherwise you're stuck consuming what is being served.