java 400_java模拟PostMan 出现400错误

在尝试使用Java模拟PostMan进行POST请求时,遇到400错误。代码中创建了JSON对象并设置了请求头,然后通过HttpURLConnection发送请求。当响应码不是200时,日志显示请求失误。问题可能在于参数设置或请求体的构造。
摘要由CSDN通过智能技术生成

java模拟PostMan 出现400错误,求大神指点一二

List> paraMapsList = sqlMap.queryForList("wf_persontask.selectBillTimeOutRemind");

List> userList = paraMapsList;

for (Map 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 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 "";

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值