Url在路径变量春天宁静的服务

时间:2015-02-09 11:35:26

标签: spring rest url

当我将电子邮件地址作为路径变量传递时,它会抛出以下错误

    Console --> 2015-02-09 16:30:06,634 WARN  - GET request for "http://localhost:8181/abc/users/testabghtmail@gmail.com" resulted in 406 (Not Acceptable); invoking error handler
Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 406 Not Acceptable
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
    at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:607)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:565)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:521)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:439)
    at RestClient.main(RestClient.java:35)

我已经尝试了很多案例,所以我终于发现了最后一个域的问题,如 .com .org 这些是国际化域名。因此,如果我通过“testabghtmail@gmail.dom”而不是“testabghtmail@gmail.com”,它将完全正常。

我的代码是

@RequestMapping(value = "users/{emailId:.*}", method = RequestMethod.GET)
    public Object searchUser(@PathVariable("emailId") String emailId){
        logger.info("Inside search user --> emailId " + emailId);
        return userService.findUserByuserId(emailId);
}

1 个答案:

答案 0 :(得分:4)

我找不到答案。我认为这是一个http规则,我们最终不能在参数中拥有域名并且可以提出请求。

因此,解决这个问题只是在网址的末尾传递一个斜线,然后就可以了。

喜欢使用“http://localhost:8181/abc/users/testabghtmail@gmail.com/”修改“http://localhost:8181/abc/users/testabghtmail@gmail.com”。并且由于Spring rest架构,它将自动省略最后一个斜杠,您将获得“testabghtmail@gmail.com”作为参数值。

如果你们找到其他东西,请告诉我。

相关问题