我想将json对象发布到mysql,它在Postman中运行良好,但是在android studio中,它显示403错误和null响应正文。
这些是我的密码
端点
@Headers("Content-Type: application/json; charset=urf-8")
@POST("cart")
fun pesanMenu(@Body data: JsonObject): Call<JsonObject>
请求
val jsonParent = JsonObject()
jsonParent.addProperty("id_user",sID)
jsonParent.addProperty("alamat_antar","Lewat Android")
val all_product_list = dbHandler?.task()
val jsonArrayPesanan = JsonArray()
for (pesan in all_product_list!!) {
val jsonPesanan = JsonObject()
jsonPesanan.addProperty("id_menu", pesan.id)
jsonPesanan.addProperty("price", pesan.priceCart)
jsonPesanan.addProperty("quantity", pesan.quantityCart)
jsonArrayPesanan.add(jsonPesanan)
}
jsonParent.add("pesanan",jsonArrayPesanan)
Log.i("JSON", jsonParent.toString())
InitRetrofit().getInstance().pesanMenu(jsonParent).enqueue(object : Callback<JsonObject> {
override fun onFailure(call: Call<JsonObject>, t: Throwable) {
// t.printStackTrace()
Log.d("RETRO", "Falure : " + "Gagal Mengirim Request")
}
override fun onResponse(call: Call<JsonObject>, response: Response<JsonObject>) {
Log.d("RETRO", "Berhasil : " + "Berhasil Mengirim Request")
// Log.e("TAG", "response 33: " + Gson().toJson(response.body()))
val result = response.code()
Log.d("PesanActivity", "response = $result")
}
})