Error Code 411 even after Content-Length: 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
so I have been experiencing an issue with the /pause request. I can do GET /currently-playing. But when I do /pause I first get 411. Trying to solve this issue with pauseConnection.setRequestProperty("Content-Length": "0");. Doesnt work. Then looked at this issue: Cant post the link to the issue lol. It was a issue on gh where someone had the same issue. Then I added setDoOutput(true) and getOutputStream.close(). I got the error 401 back. Thanks!. My final request (it still doesnt work -.-):
public static void togglePlayPause() {
try {
// Send request to pause playback
URL pauseUrl = new URL("https://api.spotify.com/v1/me/player/pause");
HttpURLConnection pauseConnection = (HttpURLConnection) pauseUrl.openConnection();
// Set the request method to PUT
pauseConnection.setRequestMethod("PUT");
// Set the required headers
pauseConnection.setRequestProperty("Authorization", "Bearer " + accessToken);
pauseConnection.setRequestProperty("Content-Length", "0");
// Enable the output stream, so we can have a request body, but don't write anything to it
pauseConnection.setDoOutput(true); // This indicates that the connection has a body, even if it's empty
// Since we're not sending any data, we don't need to write to the output stream
pauseConnection.getOutputStream().close(); // Close the stream immediately without writing anything
// Get the response code
int responseCode = pauseConnection.getResponseCode();
System.out.println("Response Code: " + responseCode);
} catch (IOException e) {
e.printStackTrace();
}
}
Labels:
- Labels:
-
Possible Bug
-
Question
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page