Android : java.io.UnsupportedEncodingException: application/json; charset=UTF-8

on Monday, January 19, 2015


I have a problem in this Android code snippet:



public Object post(String path, Object payload, Class<?> responseType) throws Exception {
URI uri = buildUri(path);
HttpPost request = new HttpPost(uri);
addHeaders(request);
request.setEntity(new StringEntity(
serialize(payload),
ContentType.APPLICATION_JSON));
return op(request, responseType);
}



'StringEntity(java.lang.String, java.lang.String)' in 'org.apache.http.entity.StringEntity' cannot be applied to '(java.lang.String, org.apache.http.entity.ContentType)'



How can I correctly convert ContentType to String? I tried the use toString(), but got an error:



java.io.UnsupportedEncodingException: application/json; charset=UTF-8



I would be grateful for your help.


Thanks.


0 comments:

Post a Comment