Skip to content

Commit

Permalink
Send content type as application/json when sending json in body param…
Browse files Browse the repository at this point in the history
…s - Fixes #175
  • Loading branch information
JMPerez committed Aug 3, 2020
1 parent 1487329 commit d7e9e79
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/spotify-web-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ var SpotifyWebApi = (function () {
if (_accessToken) {
req.setRequestHeader('Authorization', 'Bearer ' + _accessToken);
}
if (requestData.contentType) {
req.setRequestHeader('Content-Type', requestData.contentType);
}

req.onreadystatechange = function () {
if (req.readyState === 4) {
Expand All @@ -124,10 +121,13 @@ var SpotifyWebApi = (function () {
} else {
var postData = null;
if (requestData.postData) {
postData =
requestData.contentType === 'image/jpeg'
? requestData.postData
: JSON.stringify(requestData.postData);
if (requestData.contentType === 'image/jpeg') {
postData = requestData.postData;
req.setRequestHeader('Content-Type', requestData.contentType);
} else {
postData = JSON.stringify(requestData.postData);
req.setRequestHeader('Content-Type', 'application/json');
}
}
req.send(postData);
}
Expand Down

0 comments on commit d7e9e79

Please sign in to comment.