Why a Post request sends a 415 error?

Good evening.There is such a request
import decode from 'jwt-decode';
export default class AuthService {
 constructor(domain) {

 this.fetch = this.fetch.bind(this)
 this.login = this.login.bind(this)
 this.getProfile = this.getProfile.bind(this)
}

 login(username, password) {
 // Get a token
 return this.fetch('http://id.cryptofiles.org:2212/api/users/login/', {
 method: 'POST',
mode:'no-cors',
 headers: {
 "Accept": "application/json; odata=nometadata",
 "Content-Type": "application/json;odata=nometadata",

},
 'Content-Type': 'application/json',
 body: JSON.stringify({
username
password
})
 }).then(res => {
this.setToken(res.auth_token)
 return Promise.resolve(res);
})
}

 loggedIn() {
 // Checks if there is a saved token and it's still valid
 const token = this.getToken()
 return !!token && !this.isTokenExpired(token) // handwaiving here
}

 isTokenExpired(token) {
 try {
 const decoded = decode(token);
 if (decoded.exp < Date.now() / 1000) {
 return true;
}
else
 return false;
}
 catch (err) {
 return false;
}
}

 setToken(idToken) {
 // Saves a user token to localStorage
 localStorage.setItem('auth_token', idToken)
}

 getToken() {
 // Retrieves the user token from localStorage
 return localStorage.getItem('auth_token')
}

 logout() {
 // Clear user token and profile data from localStorage
localStorage.removeItem('auth_token');
}

 getProfile() {
 return decode(this.getToken());
}


 fetch(url, options) {
 // performs api calls sending the required authentication headers
 const headers = {
 "Accept": "application/json; odata=nometadata",
 "Content-Type": "application/json;odata=nometadata",

}

 if (this.loggedIn()) {
 headers['Authorization'] = 'Bearer' + this.getToken()
}

 return fetch(url, {
headers
...options
})
.then(this._checkStatus)
 .then(response => response.json())
}

 _checkStatus(response) {
 // raises an error in case the response status is not a success
 if (response.status >= 200 && response.status < 300) {
 return response
 } else {
 var error = new Error(response.statusText)
 error.response = response
 throw error
}
}
}

but the server sends a 415 error, what could be the problem?
June 5th 19 at 21:36
1 answer
June 5th 19 at 21:38
Solution
All 415 who I met talked about the mismatch of the Content-Type header with the passed request body or just unsupported Content-Type header.

Find more questions by tags HTTPSReact