[Resolved] “org.springframework.web.HttpMediaTypeNotSupportedException” angular 5

Hi All, Recently I came across this “org.springframework.web.HttpMediaTypeNotSupportedException” error while trying to hit my spring boot rest web services application from angular 5.

 

I am posting my experience because to help someone quickly.

I almost cross checked all the places many times, but I could not find the below miss which I found at last and also do remember this error says that “HttpMediaTypeNotSupportedException”, so this error can happen due to incorrect media type/media type is not set or some spelling issue.

 

In my case,

Error: “org.springframework.web.HttpMediaTypeNotSupportedException”

Resolution:

I just missed s in the header in the return this.http.post line, it should be headers, but I just mentioned s and wrote as as header.

Before Fix:

deleteSelectedStores(storeIds:number[]){
let url = AppSettings.API_ENDPOINT+”/store/deleteSelectedStores”;
let headerValues = new Headers({“Content-Type”:”application/json”,”Authorization”:”Bearer “+localStorage.getItem(“token”)});
console.log(“data”+storeIds);
console.log(“data in json “+JSON.stringify(storeIds));
return this.http.post(url, JSON.stringify(storeIds),{header:headerValues});
}

 

 

After Fix:

[html]
deleteSelectedStores(storeIds:number[]){
let url = AppSettings.API_ENDPOINT+”/store/deleteSelectedStores”;
let headerValues = new Headers({“Content-Type”:”application/json”,”Authorization”:”Bearer “+localStorage.getItem(“token”)});
console.log(“data”+storeIds);
console.log(“data in json “+JSON.stringify(storeIds));
return this.http.post(url, JSON.stringify(storeIds),{headers:headerValues});
}

[/html]

 

Feel free to share your thoughts about this post or to improve this blog better!

Leave a Reply