我正在使用环j库(https://github.com/loopj/android-async-http),它最近被更改为与API 23兼容。
当提交“put”请求时,我会将StringEntity传递到put方法中,如下所示:
client.put(CallApplication.getContext(),url, request.StringEntity, responseHandler);我的StringEntity是一个通过执行以下操作将其转换为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
发布于 2016-01-04 13:18:56
碰巧有一个
cz.msebera.android.httpclient.entity.StringEntity可以使用。谁知道呢!
无论如何干杯
发布于 2016-01-04 12:36:58
可以将名称值对添加到设置实体。
ArrayList nvp= new ArrayList();nvp.add(新BasicNameValuePair("keyname",jsonvalue));
Client.setEntity(新UrlEncodedFormEntity);
https://stackoverflow.com/questions/34591071
复制相似问题