我正在与StringEntity一起使用AndroidAsyncHttp,但不推荐使用它。在以我的方式发送json字符串给我的web服务时,还有其他方法让它工作吗?
public void getPropertyImagesAsync(final String[] params) {
JsonStructure jsonStructure = new JsonStructure();
jsonStructure.methodName = "getPropertyWorkorders";
jsonStructure.serviceName = "mobileapi";
jsonStructure.parameters = params;
String jsonString = new Gson().toJson(jsonStructure);
StringEntity entity = null;
try {
entity = new StringEntity(jsonString);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
AsyncHttpClient client = new AsyncHttpClient();
client.post(visnetawrap, BASE_URL + "/amf/gateway/?contentType=application/json", entity, "application/json", new TextHttpResponseHandler() {
@Override
public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
AppUtils.outputJsonString(s);
}
@Override
public void onSuccess(int i, Header[] headers, String s) {
AppUtils.outputJsonString(s);
}
});
}发布于 2015-08-07 03:05:43
注意一下情况,但是现在继续使用StringEntity可能会让你逃脱惩罚。
StringEntity实际上是Apache的一部分,而不是Android-异步- HTTP。Google在SDK 22中反对整个Apache,并将其从SDK 23中的存根库(M预览)中删除。据说它仍然运行在M设备上,但是你不能编译它。
不幸的是,android-异步HTTP是围绕Apache设计的.更糟糕的是,它公开了它对该API的使用,因此不能在不造成破坏的情况下对其进行更改。开发人员已经宣布了确保持续支持的计划,可能会引入对独立的Apache的依赖。
发布于 2015-08-07 03:22:18
我建议您在网络操作中使用一个库。你可以用改装。它是一个强大的库,易于使用。
http://square.github.io/retrofit/
https://stackoverflow.com/questions/31868048
复制相似问题