Skip to content

Commit cc4d81e

Browse files
Fix bug with posting items to the API
1 parent 8083383 commit cc4d81e

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/main/java/engineer/nightowl/sonos/api/resource/BaseResource.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313
import engineer.nightowl.sonos.api.util.SonosUtilityHelper;
1414
import org.apache.commons.io.IOUtils;
1515
import org.apache.http.Header;
16-
import org.apache.http.client.methods.*;
16+
import org.apache.http.client.methods.CloseableHttpResponse;
17+
import org.apache.http.client.methods.HttpDelete;
18+
import org.apache.http.client.methods.HttpGet;
19+
import org.apache.http.client.methods.HttpPost;
20+
import org.apache.http.client.methods.HttpRequestBase;
21+
import org.apache.http.client.methods.HttpUriRequest;
1722
import org.apache.http.client.utils.URIBuilder;
23+
import org.apache.http.entity.ContentType;
1824
import org.apache.http.entity.StringEntity;
1925
import org.slf4j.Logger;
2026
import org.slf4j.LoggerFactory;
2127

2228
import java.io.IOException;
2329
import java.io.InputStream;
24-
import java.io.UnsupportedEncodingException;
2530
import java.net.URISyntaxException;
2631

2732
/**
@@ -37,6 +42,7 @@ class BaseResource
3742
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
3843
/**
3944
* Sonos can provide a header describing the response type
45+
*
4046
* @see engineer.nightowl.sonos.api.enums.SonosType
4147
*/
4248
private static final String SONOS_TYPE_HEADER = "X-Sonos-Type";
@@ -232,8 +238,8 @@ <T, U> T postToApi(final Class<T> returnType, final String token, final String p
232238
try
233239
{
234240
json = OM.writeValueAsString(content);
235-
requestContent = new StringEntity(json);
236-
} catch (final JsonProcessingException | UnsupportedEncodingException e)
241+
requestContent = new StringEntity(json, ContentType.APPLICATION_JSON);
242+
} catch (final JsonProcessingException e)
237243
{
238244
throw new SonosApiClientException("Unable to convert POST request parameters", e);
239245
}

0 commit comments

Comments
 (0)