如果data-form的方式处理post,有点区别,做个记录
public String robotSpeak(String speakMsg) { log.info("机器人语音播报请求:{}", speakMsg); // header HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); //接口参数 MultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); map.add("robUuid", RobotInfoConstant.ROBOT_UUID); map.add("controlType", 1); map.add("broadcastContent", speakMsg); // 请求 HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(map, headers); ResponseEntity<String> entity = httpClientTemplate.postForEntity(RobotInfoConstant.ROBOT_SERVER_URL + RobotInfoConstant.INSTRUCTION_CONTROL_PATH, request, String.class); log.info("机器人语音播报返回结果={}", JSON.toJSONString(entity)); return "成功"; }