重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
显示样式如下,复制内容的时候使用鼠标中键进行选中
成都创新互联公司是一家专业提供西和企业网站建设,专注与成都做网站、网站制作、成都外贸网站建设、H5建站、小程序制作等业务。10年已为西和众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。打印内容:code,请求方式,url,请求头,请求体,返回json
class LoggerInterceptor : Interceptor { override fun intercept(chain: Interceptor.Chain?): Response { val orgRequest = chain!!.request() val response = chain.proceed(orgRequest) val body = orgRequest.body() val sb = StringBuilder() if (orgRequest.method() == "POST" && body is FormBody) { val body1 = body for (i in 0 until body1.size()) { sb.append(body1.encodedName(i) + "=" + body1.encodedValue(i) + ",") } sb.delete(sb.length - 1, sb.length) //打印post请求的信息 Logger.t(AppConfigs.LOGGER_NET_TAG).d("code=" + response.code() + "|method=" + orgRequest.method() + "|url=" + orgRequest.url() + "\n" + "headers:" + orgRequest.headers().toMultimap() + "\n" + "post请求体:{" + sb.toString() + "}") } else { //打印get请求的信息 Logger.t(AppConfigs.LOGGER_NET_TAG).d("code=" + response.code() + "|method=" + orgRequest.method() + "|url=" + orgRequest.url() + "\n" + "headers:" + orgRequest.headers().toMultimap()) } //返回json val responseBody = response.body() val contentLength = responseBody!!.contentLength() val source = responseBody.source() source.request(java.lang.Long.MAX_VALUE) val buffer = source.buffer() var charset = UTF8 val contentType = responseBody.contentType() if (contentType != null) { try { charset = contentType.charset(UTF8) } catch (e: UnsupportedCharsetException) { return response } } if (contentLength != 0L) { //打印返回json //json日志使用鼠标中键进行选中 Logger.t(AppConfigs.LOGGER_NET_TAG).json(buffer.clone().readString(charset)) } return response } }