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.
The android version of StringEntity
does not have a constructor which accepts a ContentType
. Use its setContentType
method instead.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다