【问题标题】:Retrofit: on failure status code return null pointer.改造:失败状态码返回空指针。
【发布时间】:2014-05-29 19:55:33
【问题描述】:

我正在使用 Retrofit 进行后端通信: 如果状态码不是 200 则回调调用失败方法。 但我想获取失败方法中的状态码,以进行进一步的代码调节

        @Override
        public void failure(RetrofitError retrofitError) {

                Logger.e("ERROR Status:", retrofitError.getResponse().getStatus() + "");

            }
        }

但是上面的代码总是给出一个空指针异常。 失败时如何获取标头的状态码。

请帮忙。

提前致谢。

【问题讨论】:

    标签: android retrofit okhttp


    【解决方案1】:

    这是一个错误。将 OkHttp 的最新版本添加到您的依赖项中。

    compile 'com.squareup.okhttp:okhttp:2.0.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
    

    【讨论】:

    • 添加这个版本会有帮助吗???编译'com.squareup.okhttp:okhttp-tests:1.5.1'
    • 看起来像测试版?
    猜你喜欢
    • 2018-07-09
    • 1970-01-01
    • 1970-01-01
    • 2016-02-07
    • 1970-01-01
    • 1970-01-01
    • 2016-02-24
    • 2021-04-09
    • 1970-01-01
    相关资源
    最近更新 更多