当前位置: 代码迷 >> 综合 >> 表单请求 formdata postman raw json 请求数据 okhttp retrofit raw json body传输请求
  详细解决方案

表单请求 formdata postman raw json 请求数据 okhttp retrofit raw json body传输请求

热度:51   发布时间:2023-12-17 05:20:22.0

在postman中,给后台传输json数据

那么在retrofit,okhttp中如何和postman一样传json呢?

val json = ArrayList<CartCheckBean>()
val cartBean = CartCheckBean()
cartBean.id = "2"
cartBean.selected = "1"
json.add(cartBean)
val body =  
RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"), Gson().toJson(json))
cartOperatePresenter.requestSelect(body)//如果RequestBody.create()过期
//可以使用下面:
val body =Gson().toJson(map).toRequestBody("application/json;charset=UTF-8".toMediaTypeOrNull())

 

  相关解决方案