有的时候Get请求方法后面加的参数是json类型的,如果不进行encode,会报错。如果是用Retrofit则不会出错。他会自动进行转。
1、
public QueryPersonResModel queryPerson(String baseUrl) throws IOException { Retrofit retrofit = createRetrofit(baseUrl); HttpService httpService = retrofit.create(HttpService.class); String json = null; JSONObject jsonObject = new JSONObject(true); jsonObject.put("departCode","iccsid"); jsonObject.put("pageSize","10"); jsonObject.put("pageNum","1"); jsonObject.put("keyWord",""); jsonObject.put("byAddColumnJSONStr","{}"); jsonObject.put("featureNum","5"); json = jsonObject.toString(); HashMap<String, String> params = new HashMap<>(); params.put("conditionParam",json); Call<QueryPersonResModel> call = httpService.queryPerson(params); Log.i(TAG, "call:" + call); Response<QueryPersonResModel> repo = call.execute(); Log.i(TAG, "repo:" + repo); if (repo == null || repo.body() == null) { return null; } return repo.body(); }
其他的就是普通的流程和Get