java模拟postMan请求OA接口报400错误

   **今天在做项目时需要请求一个OA接口,在postMan中可以请求并且访问成功,但是在java代码中,数据是一样的,却报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();
   //组装的数据和postMan里面的数据一致
    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("Connection", "Keep-Alive");
        conn.setRequestProperty("Charset", "UTF-8");
        byte [] data = (object.toString()).getBytes();
        conn.setRequestProperty("Content-Length", 
        String.valueOf(data.length));
        conn.setRequestProperty("Content-Type", "application/json");
        //在调取TOKEN接口时已经设为了全部变量,这里是有值的
        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("-------请求出现415错误--------");
        }
        out.flush();
        out.close();
    } catch (Exception e) {
        logger.info("------------------------------------------");
    }
    return "";
}`
阅读 5.2k
1 个回答

415是后台不支持的Content-type,conn.setRequestProperty("Content-Type", "aapplication/json");拼写错误

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题