Android 更新获取 请求头 Rxjava+Retrofit2 响应头(Headers)

你的打赏,是对我最大的支持:

 

 

 

 

 

 

在Data 前面添加Response ->  Response data

    @FormUrlEncoded
    @POST("00000000000000000")
    Observable> coinextract(@Header("authorization") String apikey, 
   @FieldMap HashMap hashMap);

authorization:请求头字段 

                            ApiFactory.getInstance()
                            .coinextract(kv.decodeString("tokenId"), hashMap)
                            .compose(RxSchedulers.io_main())
                            .subscribe(new Consumer>() {
                                @Override
                                public void accept(Response data) throws Exception {

                                    //替换原来的tokenId
                                    String str = data.raw().headers("authorization").toString().substring(1, data.raw().headers("authorization").toString().length() -1);
                                    kv.encode("tokenId", str);

                                    if (data.body().getCode() == 200) {

                                        dialog.dismiss();
                                        finish();
                                        t(data.body().getMsg());
                                    } else {
                                        dialog.dismiss();
                                        t(data.body().getMsg());
                                    }

                                }


                            }, new Consumer() {
                                @Override
                                public void accept(Throwable throwable) throws Exception {

                                }
                            });

 

   //替换原来的tokenId
                                    String str = data.raw().headers("authorization").toString().substring(1, data.raw().headers("authorization").toString().length() -1);
                                    kv.encode("tokenId", str);

substring:截取字符: 
 

data.raw().headers("authorization").toString().substring(1, data.raw().headers("authorization").toString().length() -1);

注意:
data.raw().headers("authorization").toString() 这个是一串数组 :所以用到截取字符 去掉[]

 

kv.encode("tokenId", str); 这个是一款插件 MMKV自己取看

 

 

完整的log
2019-09-30 13:25:35.279 30451-30451/com.overthrow E/CurrencyActivity: 1accept: Server: nginx
    Date: Mon, 30 Sep 2019 05:25:36 GMT
    Content-Type: application/json;charset=UTF-8
    Transfer-Encoding: chunked
    Connection: keep-alive
    authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyZDlmOGVjM2ZjYTI0NDIzYmIzNjdmZjI4YWQ5ZTkwMiIsImV4cCI6MTU3MDA4MDMzNSwidXNlciI6eyJpZCI6IjJkOWY4ZWMzZmNhMjQ0MjNiYjM2N2ZmMjhhZDllOTAyIiwib3BlbklkIjpudWxsLCJ0b2tlbklkIjpudWxsLCJ1c2VybmFtZSI6IjExNDIxMjA5NTBAcXEuY29tIiwicGFzc3dvcmQiOiI4OWI5OWZjNTA1MWUxZWYwMTA3YzE0OTA1MTU4ZTEzZSIsImFjY291bnRQYXNzV29yZCI6Ijg5Yjk5ZmM1MDUxZTFlZjAxMDdjMTQ5MDUxNThlMTNlIiwic3RhdHVzIjoxLCJlbWFpbCI6IjExNDIxMjA5NTBAcXEuY29tIiwicmVhbE5hbWUiOjAsInNhbHQiOiI1NGNhZmNmYjE1YTkzNjE5YTBjODRhMGRkN2M5NzUzMyIsInVzZXJDb2RlIjoiMTAwNDEwNzMiLCJpbnZhdGVVc2VyIjpudWxsLCJoYXNFbWFpbCI6MSwiaGFzUGhvbmUiOjEsImxhc3RMb2dpbklwIjpudWxsLCJwaG9uZSI6Iis4NiAxODU4MDEwOTgyNCIsImludmF0ZUNvZGUiOiJjYTRiYWIwNWUxMzA0NzMyOTYxOTBhNmMxYjk0MjBiMSIsImxvZ0RUTyI6bnVsbCwiY3RjRGVhbFN0YXRlIjpudWxsLCJnb29nbGVTdGF0ZSI6bnVsbCwiZXhhbVN0YXRlIjpudWxsLCJnb29nbGVLZXkiOm51bGwsImNyZWF0ZVRpbWUiOm51bGwsIm1lcmNoYW50IjoxfSwiaWF0IjoxNTY5ODIxMTM1LCJ0b2tlbnR5cGUiOiI3ZWJpdF93ZWIifQ.QNU2cQwokn5fQqawFN_qDryG_Aiv9aKkwMpO-NVtndR2O1z-TrcbJxxuW8pwB-gvH9eh31aUfonOrxCF_z3A1Q
 


怎么输出 Data中数据

Android 更新获取 请求头 Rxjava+Retrofit2 响应头(Headers)_第1张图片

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(two,Android,java)