一、Post提交
在ApiService接口中定义Post请求,其他代码书接上回 Retrofit框架的简单使用(上)
/**
* Post提交方式,请求参数goodsId=xxx
* @FormUrlEncoded :表单形式提交
*/
@POST("goods/relative")
@FormUrlEncoded //表单形式提交
fun testPost2(@Field("goodsId") goodsId: String): Call<String>
/**
* 参数为map形式。请求参数: password=xxx&username=xxxxx
*/
@POST("goods/relative")
@FormUrlEncoded //表单形式提交
fun testPost3(@FieldMap mapData: Map<String,String>): Call<String>
/**
* (@Body data:HashMap<String,String>):这里不一定是String ,你可以传入具体类型,比如数据库表的实体类。
* ,要想传入的参数是Json格式的话,需要修改请求格式,
* 把ScalarsConverterFactory.create() 替换成 GsonConverterFactory.create()
* var retrofit = Retrofit.Builder()
* .baseUrl(ApiService.BASE_URL)
* .addConverterFactory(GsonConverterFactory.create()) //替换处
* .client(okHttpClient)
* .build()
*/
@POST("goods/relative")
fun testPost(@Body data:HashMap<String,String>): Call<String>