package com.swago.baseswago.http

import android.util.Log
import okhttp3.FormBody
import okhttp3.Interceptor
import okhttp3.Response
import java.net.URLDecoder

/**
 *@date 2022/2/28 15:42
 *description:
 */
class EncodeInterceptor : Interceptor {

    private var decodeValue:String?= null

    override fun intercept(chain: Interceptor.Chain): Response {
        val requestT = chain.request()
        requestT.body?.let {
            if (it is FormBody){
                if (it.size == 0){
                    Log.d("加密","无参数")
                }else{
                    for (i in 0 until it.size) {
                        val encodeValue = it.encodedValue(i)
                        decodeValue = URLDecoder.decode(encodeValue, "UTF-8")
                        Log.d("加密参数","${it.encodedName(i)}---${decodeValue.toString()}")
                    }
                    Log.d("加密","参数个数${it.size}")
                }
            }
        }


        return chain.proceed(requestT)
    }
}