java模拟PostMan 出现400错误,求大神指点一二
List<Map<String, Object>> paraMapsList = sqlMap.queryForList("wf_persontask.selectBillTimeOutRemind");
List<Map<String, Object>> userList = paraMapsList;
for (Map<String, Object> userListmap : userList) {
userListmap.put("thirdUserId", userListmap.get("id"));
userListmap.put("registerCode", "3001");
userListmap.put("thirdLoginName", userListmap.get("ownername"));
userListmap.put("thirdName", userListmap.get("name"));
userListmap.put("thirdCode", userListmap.get("NO"));
userListmap.put("thirdMobile", null);
userListmap.put("thirdEmail", userListmap.get("EMAIL"));
userListmap.remove("id");
userListmap.remove("PROCESSNAME");
userListmap.remove("name");
userListmap.remove("assignee");
userListmap.remove("EMAIL");
userListmap.remove("NO");
userListmap.remove("ownername");
bindUSERPost(userListmap);
}
public String bindUSERPost(Map<String, Object> userListmap) {
JSONArray jsonArray = new JSONArray();
jsonArray.add(userListmap);
JSONObject object = new JSONObject();
object.put("userlist", jsonArray);
try {
logger.info(object.toJSONString()+"---------------------------");
URL realUrl = new URL(BINDIND);
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Charset", "UTF-8");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("token", tokenID);
conn.connect();
DataOutputStream out =new DataOutputStream(conn.getOutputStream());
out.write((jsonArray.toString()).getBytes());
logger.info(conn.getResponseCode()+"请求返回的状态码");
if (conn.getResponseCode() == 200) {
logger.info("---------------请求成功-----------------");
//请求返回的数据
InputStream in = conn.getInputStream();
byte[] datas = new byte[in.available()];
in.read(datas);
String msg = new String(datas);
}else {
logger.info("-------请求失误,请检查参数--------");
}
out.flush();
out.close();
} catch (Exception e) {
logger.info("------------------------你有毒你有毒------------------");
}
return "";
}
个人认为可以从下面几个方面入手排查
确认url是否正确呢,请求的资源是否存在
检查入参的参数是否完整,格式类型是否符合
确认服务端是否正常,是否是对服务端异常的处理,重写了httpstatus