마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

레트로핏 인터셉터 body 익셉션

0 추천
val requestToken = tokenRefresh()
val responseToken = chain.proceed(requestToken)
private fun tokenRefresh(): Request {
    var formBody = FormBody.Builder()
        .add("key",value)
        .build()

    val request = Request.Builder()
        .url("api url")
        .post(formBody)
        .build()
    return request
}

다음과 같은 형태로 하고 

val test = responseToken.body?.string() 해서

test를 로그찍어보면 exception.HttpMediaTypeNotSupportedException ,

Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported 

이나오고 있습니다 

addHeader("Content-Type", "application/json")

기존에 이걸 쓰고 있는데요 저 위에서 request에 addheader을 넣어줘도 똑같은 에러가 나오는데 어떻게해야될까요?

post api 입니다

수원통학러 (3,570 포인트) 님이 2022년 4월 5일 질문

1개의 답변

0 추천

The HTTP 415 Unsupported Media Type client error response code indicates that the server refuses to accept the request because the payload format is in an unsupported format.

The format problem might be due to the request's indicated Content-Type or Content-Encoding, or as a result of inspecting the data directly.

해당 에러는 서버가 해당 데이터 타입을 지원하지 않아서 생기는 에러라고 MSDN 문서에 나오네요. 서버에서 데이터가 받아지는지 체크해 보세요. post man같은데서도 똑같은 테스트를 해보시구요.

spark (227,830 포인트) 님이 2022년 4월 5일 답변
...