直接上代码
调用接口传参为application/json格式
public String updateAqzxUser(TPolice tPolice, String Authorization,String depids,String id ) throws IOException { String uplevelArr = ""; String con = ""; for (String s : tPolice.getRoleids()) { uplevelArr += con + "\"" + s + "\""; con = ","; } final String CONTENT_TYPE_TEXT_JSON = "text/json"; DefaultHttpClient client = new DefaultHttpClient(); String jsonParams = "{ \"id\": \""+id+"\",\"name\":\"" + tPolice.getPoliceName() + "\",\"department\":\"" + tPolice.getOrgCode() + "\",\"contact\":\"" + tPolice.getTel() + "\",\"depids\":[ \""+depids+"\"],\"deviceCode\":\"\",\"idCard\":\"" + tPolice.getIdcard() + "\",\"password\":\"97047690c82e15930277c2ddba97647b\",\"pcard\":\"" + tPolice.getPoliceNum() + "\",\"photo\":\"\",\"roleids\":[" + uplevelArr + "],\"state\":1,\"featureList\":[],\"job\":[{\"code\":\"200001\",\"name\":\"民警\"}],\"isAdmin\":0,\"politicsStatusCode\":\"\",\"personalInformation\":\"\",\"jobDescription\":\"\"}"; String url = aqzxurl + "/user/editUser"; //调用音频组地址 HttpPost httpPost = new HttpPost(url); httpPost.setHeader("Authorization", Authorization); httpPost.setHeader("Content-Type", "application/json;charset=UTF-8"); StringEntity se = new StringEntity(jsonParams, "UTF-8"); se.setContentType(CONTENT_TYPE_TEXT_JSON); httpPost.setEntity(se); HttpResponse response2 = null; response2 = client.execute(httpPost); HttpEntity entity2 = null; entity2 = response2.getEntity(); String s2 = EntityUtils.toString(entity2, "UTF-8"); // JSONObject js01 = (JSONObject) JSONObject.parse(s2); // List<Map<String, Object>> list = (List<Map<String, Object>>) js01.get("data"); System.out.println("===="+s2); return s2; }
这里传参有点多 通过字符串转义将参数转为application/json。