我正在使用 loopj 库(https://github.com/loopj/android-async-http),它最近已更改为与 API 23 兼容。
当提交一个“put”请求时,我会StringEntity
像这样传递到 put 方法:
client.put(CallApplication.getContext(),url, request.StringEntity, responseHandler);
MyStringEntity
是一个通过执行以下操作转换为 Json 的对象:
public static StringEntity getJsonFromObject(Object object) {
String json = new Gson().toJson(object);
StringEntity stringEntity = null;
try {
stringEntity = new StringEntity(json, HTTP.UTF_8);
stringEntity.setContentType("text/json");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return stringEntity;
}
现在我需要使用HttpEntity
它,目前尚不清楚如何获得它。如何将我的 json 字符串放入HttpEntity
?