调用接口时报:Required String parameter '' is not present

    这个问题我是springboot项目用RestTemplate()调用方法时报的错,附上我的理解,所调用接口方法required = false 必须为false,如果为true则可能有限制

org.springframework.web.client.HttpClientErrorException$BadRequest: 400 : [{"timestamp":"2020-02-06T10:06:47.302+0000","status":400,"error":"Bad Request","message":"Required String parameter 'inputcode' is not present","trace":"org.springframework.web.bind.MissingServletRequ... (8821 bytes)]
	at 

我的代码是:

@ApiOperation(value = "人脸识别返回数据",notes = "人脸识别返回数据")
    @RequestMapping(value = "/facecheck",method = RequestMethod.POST)
    public Map face(@RequestParam(value = "urlString",required = false) String urlString) {
         String src = "http://localhost:8082/sys/sendmessagecode/sendcodeyesorno";
        MultiValueMap map = new LinkedMultiValueMap();
        map.add("inputcode","9098");
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
        HttpEntity httpEntity = new HttpEntity(headers,map);
        ResponseEntity exchange = new RestTemplate().exchange(src,HttpMethod.GET,httpEntity, Map.class);
        return exchange.getBody();

    }

String src = “http://localhost:8082/sys/sendmessagecode/sendcodeyesorno”;
这个地址对应的代码是:

@ApiOperation(value = "查询验证码是否正确",notes = "查询验证码是否正确")
    @RequestMapping(value = "/sendcodeyesorno",method = RequestMethod.GET)
    public Map sendCodeYesOrNo(@ApiParam(name = "输入的码",value = "输入的码",required = true)
                                                  @RequestParam(value = "inputcode",required = true) String inputcode){
        Map mapReturn = sendSmsMessage(phoneNumbercheck);
        String code = mapReturn.get("code");
        if (code.equalsIgnoreCase(inputcode)){
         return  mapReturn;
        }
        mapReturn.put("code", "验证码:["+inputcode+"]输入不正确,请重新输入!");
        return  mapReturn;
    }

解决方式是:
所调用地址的方法中(上面方法)required = true 这个必须改为required = false

你可能感兴趣的:(java,报错总结)