Skip to content

Instantly share code, notes, and snippets.

@dokinkon
Created November 11, 2018 00:50
Show Gist options
  • Save dokinkon/e998c1238bd657dcb7aa297e3c2095f2 to your computer and use it in GitHub Desktop.
Save dokinkon/e998c1238bd657dcb7aa297e3c2095f2 to your computer and use it in GitHub Desktop.
Retrofit如何避免multipart-form-data中的參數被雙引號夾起來
inline fun <reified T> createWebService(okHttpClient: OkHttpClient, url: String): T {
val retrofit = Retrofit.Builder()
.baseUrl(url)
.client(okHttpClient)
.addConverterFactory(ScalarsConverterFactory.create()) // <--- 避免產生雙引號在multipart-formdata的參數中
.addConverterFactory(GsonConverterFactory.create()) // <-- ScalarsConverterFactory要放在GsonConverterFactory之前
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build()
return retrofit.create(T::class.java)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment