I am trying to connect from JS fetch request to my Java Spring Boot server in the JSON relationship but it keeps getting error that text/plain content type is not supported even if i changed in fetch request headers to application/json , it keeps sending text/plain mediaType.
#Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content-Type 'text/plain
1 messages · Page 1 of 1 (latest)
<@&987246527741304832> please have a look, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
am getting a "HttpMediaTypeNotSupportedException" error with the message "Content-Type 'text/plain' not supported".
This error occurs because the server is expecting a JSON content type, but the request is being sent with a 'text/plain' content type. To resolve this issue, you need to set the correct content type in your fetch request.
In your JavaScript code, make sure to set the 'Content-Type' header to 'application/json' before sending the request. Here's an example:
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
// Handle response data
})
.catch(error => {
// Handle error
});
By setting the 'Content-Type' header to 'application/json', you are informing the server that you are sending JSON data in the request body. This should resolve the "HttpMediaTypeNotSupportedException" error.
i changed , it keeps sending text/plain content type