Retrofit 打印log时,中文会显示类似%E8%BE%BD字符
Posted liyanli-mu640065
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Retrofit 打印log时,中文会显示类似%E8%BE%BD字符相关的知识,希望对你有一定的参考价值。
https://blog.csdn.net/honghailiang888/article/details/54289632?utm_source=blogxgwz6
参照android Retrofit2.1.0设置编码格式GBK 的文章。
OkHttpClient.Builder builder = new OkHttpClient().newBuilder(); /***lyl TODO 下面一行代码加入https的接口访问**/ //builder.sslSocketFactory(getSSLSocketFactory(context)); builder.addInterceptor(new Interceptor() { @Override public Response intercept(Interceptor.Chain chain) throws IOException { Request original = chain.request(); // Request customization: add request headers // Log.d(TAG, fdata);StringUtil.encryptAsDoNet(fdata, 1) // Log.d(TAG, "加密后:"+DESUtils.encryptAsDoNet(fdata, 1)); Request.Builder requestBuilder = null; try { requestBuilder = original.newBuilder() .addHeader("androidorios", "android"); } catch (Exception e) { LogUtil.e(TAG,"---create--addhead---"+e.toString()); } Request request = requestBuilder.build(); request = requestBuilder.post(RequestBody.create(MediaType.parse("application/x-www-form-urlencoded;charset=utf-8"), URLDecoder.decode(bodyToString(request.body()), "UTF-8"))) .build(); return chain.proceed(request); } });
就可以解决问题。
以上是关于Retrofit 打印log时,中文会显示类似%E8%BE%BD字符的主要内容,如果未能解决你的问题,请参考以下文章
Retrofit2.0+OkHttp打印Request URL(请求地址参数)
Retrofit2.0+OkHttp打印Request URL(请求地址参数)
Android Retrofit2 0 查看log和JSON字符串(HttpLoggingInterceptor)