일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
- Parameter specified as non-null is null
- 에러 메시지를 잘보자 ^^
- 플러터
- 2D 그래픽 라이브러리
- 배움순서
- pubspec
- 2D graphics library
- 안드로이드
- 플러터 테스트
- Refresh Tocken
- 테스트 주도 개발론
- pubspec.yaml
- Same parameter
- 토큰갱신
- dart
- 안드로이드를 위한
- widget test
- 인코딩방지
- retorift
- dart test
- Flutter
- refresh 토큰
- TDD 개발 방법론
- permission_handler
- 객체 지향 설계
- SOLID 원칙
- 다트
- 8시간 삽질
- Android
- 다트 테스트
- Today
- Total
Landroid
Retrofit @Query 인코딩 방지 본문
안녕하세요 ~ Landroid입니다!
retrofit을 사용하실 때 @Query를 자주 사용하실 텐데요.
https://address.com/user?name=안녕
https://address.com/user?name=%EC%95%88%EB%85%95
간혹 위에처럼 들어간 값이 자동으로 utf-8로 인코딩 되어 원하는 주소가 나오지 않은 불상사도 자주 발생합니다.
오늘은 @Query 문에 인코딩을 방지하는 방법에 대해 설명하겠습니다.
encoded = true

먼저 첫 번째 방법은 @Query 속성 중 하나인 encoded 값을 true로 설정해주는 것입니다.
encoded가 true이면 @Query에 들어오는 값은 인코딩이 된 것임을 알리기 때문에
자동으로 인코딩 되는 것을 방지할 수 있습니다.
그러나 가끔씩 해결이 안 될 때가 있습니다.
분명 encoded 값을 true로 줬는데 계속 무시하고 인코딩을 하는 경우도 있습니다.
아래가 대표적인 사례입니다.
https://github.com/square/retrofit/issues/1199
Using @QueryMap(encoded = true) will still encode values · Issue #1199 · square/retrofit
I'm using QueryMap like this: interface ProjectApi { @GET("projects/") Observable getProjects(@QueryMap(encoded = true) Map<string, string=""> params); } final Proje...</string,>
github.com
그나마 해결책이 있다면 밑 나와 있는 대로 @Url를 사용해서 url을 직접 지정하는 방식이 있습니다.
https://futurestud.io/tutorials/retrofit-2-how-to-use-dynamic-urls-for-requests
Retrofit 2 — How to Use Dynamic Urls for Requests
All modern Android apps need to do network requests. Retrofit offers you an extremely convenient way of creating and managing network requests. From asynchronous execution on a background thread, to automatic conversion of server responses to Java objects,
futurestud.io
이걸로 도움되길 바라며,
이만 마치도록 하겠습니다. ^^7