Skip to content

Commit 81f1a77

Browse files
authored
Send content type as application/json when sending json in body params - Fixes #175 (#179)
1 parent 8f6faee commit 81f1a77

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/spotify-web-api.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ var SpotifyWebApi = (function () {
9898
if (_accessToken) {
9999
req.setRequestHeader('Authorization', 'Bearer ' + _accessToken);
100100
}
101-
if (requestData.contentType) {
102-
req.setRequestHeader('Content-Type', requestData.contentType);
103-
}
104101

105102
req.onreadystatechange = function () {
106103
if (req.readyState === 4) {
@@ -124,10 +121,13 @@ var SpotifyWebApi = (function () {
124121
} else {
125122
var postData = null;
126123
if (requestData.postData) {
127-
postData =
128-
requestData.contentType === 'image/jpeg'
129-
? requestData.postData
130-
: JSON.stringify(requestData.postData);
124+
if (requestData.contentType === 'image/jpeg') {
125+
postData = requestData.postData;
126+
req.setRequestHeader('Content-Type', requestData.contentType);
127+
} else {
128+
postData = JSON.stringify(requestData.postData);
129+
req.setRequestHeader('Content-Type', 'application/json');
130+
}
131131
}
132132
req.send(postData);
133133
}

0 commit comments

Comments
 (0)