Когда API Gateway кодирует тело запроса на Base64? ⇐ Android
Когда API Gateway кодирует тело запроса на Base64?
Если я устанавливаю тип контента через Interceptor из okhttp , шлюз API будет кодировать тело запроса в Base64.
/li>
Если я устанавливаю тип содержимого через заголовки аннотацию из модернизации , Sever не будет кодировать в Base64.
< /ol>
Я понимаю, что необходимость декодировать от Base64, я не понимаю, в чем разница на стороне клиента? < /p>
// First case
object ApiFactory {
private val baseUrl = ""
fun create(): Api {
val client = OkHttpClient().newBuilder()
.addInterceptor(ContentTypeHeaderInterceptor())
.addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
.build()
return createRetrofitApi(client, baseUrl)
}
inline fun createRetrofitApi(client: OkHttpClient, baseUrl: String, converterFactory: Converter.Factory? = null): T {
return Retrofit.Builder()
.addCallAdapterFactory(adapterFactory)
.addConverterFactory(converterFactory)
.baseUrl(baseUrl)
.client(client)
.build()
.create(T::class.java)
}
}
class ContentTypeHeaderInterceptor: Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
.newBuilder()
.header("Content-Type", "application/json")
.build()
return chain.proceed(request)
}
}
< /code>
// Second case
interface Api {
@Headers("Content-Type: application/json")
@POST("signin")
suspend fun signIn(
@Body body: SignInRequest
): ResponseOkHttp
}
< /code>
// Logcat
// First case
--> POST https://example.com/signin
Content-Length: 1096
Content-Type: application/json
{"IdToken":"..."}
--> END POST (1096-byte body)
// Second case
--> POST https://example.com/signin
Content-Type: application/json
Content-Length: 1096
{"IdToken":"..."}
--> END POST (1096-byte body)
Подробнее здесь: https://stackoverflow.com/questions/794 ... -to-base64
Если я устанавливаю тип контента через Interceptor из okhttp , шлюз API будет кодировать тело запроса в Base64.
/li>
Если я устанавливаю тип содержимого через заголовки аннотацию из модернизации , Sever не будет кодировать в Base64.
< /ol>
Я понимаю, что необходимость декодировать от Base64, я не понимаю, в чем разница на стороне клиента? < /p>
// First case
object ApiFactory {
private val baseUrl = ""
fun create(): Api {
val client = OkHttpClient().newBuilder()
.addInterceptor(ContentTypeHeaderInterceptor())
.addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
.build()
return createRetrofitApi(client, baseUrl)
}
inline fun createRetrofitApi(client: OkHttpClient, baseUrl: String, converterFactory: Converter.Factory? = null): T {
return Retrofit.Builder()
.addCallAdapterFactory(adapterFactory)
.addConverterFactory(converterFactory)
.baseUrl(baseUrl)
.client(client)
.build()
.create(T::class.java)
}
}
class ContentTypeHeaderInterceptor: Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
.newBuilder()
.header("Content-Type", "application/json")
.build()
return chain.proceed(request)
}
}
< /code>
// Second case
interface Api {
@Headers("Content-Type: application/json")
@POST("signin")
suspend fun signIn(
@Body body: SignInRequest
): ResponseOkHttp
}
< /code>
// Logcat
// First case
--> POST https://example.com/signin
Content-Length: 1096
Content-Type: application/json
{"IdToken":"..."}
--> END POST (1096-byte body)
// Second case
--> POST https://example.com/signin
Content-Type: application/json
Content-Length: 1096
{"IdToken":"..."}
--> END POST (1096-byte body)
Подробнее здесь: https://stackoverflow.com/questions/794 ... -to-base64
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение