【问题标题】:Spring Web Service Error : 406 Not AcceptableSpring Web 服务错误:406 不可接受
【发布时间】:2016-04-04 12:19:47
【问题描述】:

我在 Spring Controller Class 中为 rest web service 编写了这段代码。构建项目后,我尝试使用 service 使用 Restful-Client

RestService 代码:-

@RequestMapping(value="/someurl/{prm_passPhraseCode}/{prm_email}", method= RequestMethod.POST)
        public @ResponseBody User sendResetLink(@PathVariable("prm_passPhraseCode") String prm_sPassPhrase, @PathVariable("prm_email") String prm_sEmail , HttpServletRequest prm_ObjRequest, HttpServletResponse prm_ObjResponse){

......
..... //some more logical Code.

return new User(); //just dummy object for reference.
}

这里是我尝试访问 URL 的方式。我选择了方法类型为post。 我还添加了两个标题

  1. Content-Type : application/json
  2. Accept : application/json

网址http://127.0.0.1:8080/webservice.staff.backend/someurl/23812397997713/kumarvikrant625@gmail.com

尽管我的所有其他 Rest 服务 url 无论是 GET 还是 POST 都可以正常工作。 我也尝试更改method = RequestMethod.GET,但仍然出现相同的错误。

错误:-

Status Code 406 : The resource identified by this request is only capable of 
generating responses with characteristics not acceptable according to the request "accept" headers.

如果有人有想法请帮忙。

【问题讨论】:

  • 似乎 sendResetPasswordLink 没有反映在请求映射中
  • 不反映是什么意思??实际上没有得到你..@Benchik
  • 喜欢@RequestMapping(value="/someurl/sendResetPasswordLink/{prm_passPhraseCode}/{prm_email}"

标签: java json spring web-services rest


【解决方案1】:

您的网址未正确映射,您缺少sendResetPasswordLink

@RequestMapping(value="/someurl/sendResetPasswordLink/{prm_passPhraseCode}/{prm_email}", method= RequestMethod.POST)

【讨论】:

  • 对不起。我已经更新了使用 rest-Client 访问的 url。现在说
  • 如果还是有同样的错误,你应该检查其他映射的url,看看它们之间是否有冲突
  • 我确信我的本地不存在这样的url,因为/someurl 在该控制器类中是唯一标识的。谢谢,但仍然完全荒谬@Rafik
【解决方案2】:

试试这个..也许它可以工作......

@RequestMapping(value="/someurl/{prm_passPhraseCode}/{prm_email}",headers="Accept=*/*", method= RequestMethod.POST)

【讨论】:

  • 已经尝试过这个技巧但没有得到解决方案@Md shifattul
猜你喜欢
  • 2015-03-17
  • 1970-01-01
  • 2017-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-07
  • 1970-01-01
  • 2013-04-26
相关资源
最近更新 更多