Retrofit post提交,一般都Content-Type: application/json为请求头,用来告诉服务端消息主体是序列化后的 JSON 字符串。注解使用(@Body ChatBean data ),这样请求的时候,data自动被转换成json。
可是有的API请求要求是form表单提交,Content-Type: application/x-www-form-urlencoded,retrofit的Service怎么写,记录如下:
@POST("oauth/token")
@FormUrlEncoded
@Headers("Content-Type: application/x-www-form-urlencoded")
fun getAppTokenData(@Header("Authorization") authorization: String, @FieldMap data: HashMap<String, String>): Call<SucLoginBean>
参考:https://stackoverflow.com/questions/35693680/how-to-send-form-data-in-retrofit2-android