首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LoopJ AndroidAsyncHttp StringEntity问题

LoopJ AndroidAsyncHttp StringEntity问题
EN

Stack Overflow用户
提问于 2015-08-07 00:53:49
回答 2查看 573关注 0票数 0

我正在与StringEntity一起使用AndroidAsyncHttp,但不推荐使用它。在以我的方式发送json字符串给我的web服务时,还有其他方法让它工作吗?

代码语言:javascript
复制
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);
        }
    });
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-08-07 03:05:43

注意一下情况,但是现在继续使用StringEntity可能会让你逃脱惩罚。

StringEntity实际上是Apache的一部分,而不是Android-异步- HTTP。Google在SDK 22中反对整个Apache,并将其从SDK 23中的存根库(M预览)中删除。据说它仍然运行在M设备上,但是你不能编译它。

不幸的是,android-异步HTTP是围绕Apache设计的.更糟糕的是,它公开了它对该API的使用,因此不能在不造成破坏的情况下对其进行更改。开发人员已经宣布了确保持续支持的计划,可能会引入对独立的Apache的依赖。

票数 0
EN

Stack Overflow用户

发布于 2015-08-07 03:22:18

我建议您在网络操作中使用一个库。你可以用改装。它是一个强大的库,易于使用。

http://square.github.io/retrofit/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31868048

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档