1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| //post json @POST Call<String> reJson(@Url String url, @Body RequestBody body);
HashMap<String, String> params = new HashMap<>(); params.put("phone_num", "123"); JSONObject json = new JSONObject(params); RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=utf-8"), json);//转化类型
//post params @POST @FormUrlEncoded Call<String> reParams(@Url String url, @FieldMap Map<String, String> map);
HashMap<String, String> hashMap = new HashMap<>(); hashMap.put("user", "test"); //post file map @POST @Multipart Call<String> reUploadFile(@Url String url, @PartMap Map<String, RequestBody> params); File file = new File(""); Map<String, RequestBody> hashMap = new HashMap<>(); hashMap.put("json", RequestBody.create(MediaType.parse("text/plain"), "jsonargs"));//键值对 hashMap.put("file\"; filename=\"" + file.getName(), RequestBody.create(MediaType.parse("multipart/form-data"), file));//文件
|