使用Spring RequestMapping path param编码的斜杠(%2F)给出了HTTP 400 [英] Encoded slash (%2F) with Spring RequestMapping path param gives HTTP 400

查看:504
本文介绍了使用Spring RequestMapping path param编码的斜杠(%2F)给出了HTTP 400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是重复的引用问题,因为它是Spring特定的。无论谁补充说(在事实发生3年后),他们都懒得去阅读问题或评论主题,看看真正的答案是什么。被接受的答案并不完全是答案,但答案的作者从来没有回来,像我问的那样编辑它。



,Spring 3.1给出了一个400错误,客户端发送的请求在语法上不正确()。当标记参数包含URL编码的斜杠(%2F)时,例如 https://somewhere.com/ws/stuff/lookup/resourceId/287559/token/R4o6lI%2FbBx43/userName/jim 没有%2F一切正常。第三方已经在调用此服务(当然!),所以我至少在短期内无法更改他们发送的内容。关于如何在服务器端解决这个问题的任何想法?



这个问题在这里描述得非常好 https://jira.springsource.org/browse/SPR-8662 ,虽然这个问题与UriTemplate有关,我不知道这个问题。 p
$ b $ pre $ code $ @ $ @ $ @ $ @ b $ b @Controller
public class StuffController {
@RequestMapping(value =/ ws / stuff / lookup / resourceId / {resourceId} / token / {token} / userName / {userName},method = RequestMethod.GET)
public @ResponseBody
字符串provisionResource(@PathVariable(resourceId)字符串resourceId,@PathVariable(token)字符串标记,@PathVariable(userName)字符串userName,ModelMap modelMap,
HttpServletRequest请求,HttpServletResponse响应){
返回句柄(resourceId,userName,request,token,modelMap);
}
}

注意:这是Glassfish 3.1.2,起初它是灰熊/ Glassfish不接受斜线,但是
$ b

-Dcom.sun.grizzly.util.buf.UDecoder.ALLOW_ENCODED_SLASH = true



解决了这个问题。

asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-2.http.encoded-slash -enabled = true



似乎没有帮助。

解决方案

这可能是您的答案: urlencoded正斜杠破坏URL



我建议不要将它放在路径中,而是将其移至请求参数。



<您可以将RequestMapping更改为

 >  @RequestMapping(value =/ ws / stuff / lookup / resourceId / **,method = RequestMethod.GET)

,然后从请求对象手动解析路径变量。


This is not a duplicate referenced question, because it is Spring specific. Whoever added that (3 years after the fact!) didn't bother to read the question or comment thread to see what the real answer was. The accepted answer isn't quite the answer, but the author of the answer never came back and edited it like I asked.

Given the restful method below, Spring 3.1 gives a 400 error with "The request sent by the client was syntactically incorrect ()." when the token parameter contains a URL encoded slash (%2F), for example "https://somewhere.com/ws/stuff/lookup/resourceId/287559/token/R4o6lI%2FbBx43/userName/jim" Without the %2F everything works fine. A 3rd party is already calling this service (of course!) so I can't change what they send, in the short term at least. Any ideas on how to work around this on the server side?

This problem is described very well here https://jira.springsource.org/browse/SPR-8662 though that issue is related to UriTemplate which I am not using that I can tell.

@RequestMapping("/ws/stuff/**")
@Controller
public class StuffController {
  @RequestMapping(value = "/ws/stuff/lookup/resourceId/{resourceId}/token/{token}/userName/{userName}", method = RequestMethod.GET)
   public @ResponseBody
   String provisionResource(@PathVariable("resourceId") String resourceId, @PathVariable("token") String token, @PathVariable("userName") String userName, ModelMap modelMap,
         HttpServletRequest request, HttpServletResponse response) {
      return handle(resourceId, userName, request, token, modelMap);
   }
}

Note: This is on Glassfish 3.1.2, and at first it was Grizzly/Glassfish not accepting the slash, but

-Dcom.sun.grizzly.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

fixed that.

asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-2.http.encoded-slash-enabled=true

didn't seem to help.

解决方案

This could be your answer: urlencoded Forward slash is breaking URL

I would suggest not putting that in the path, move it to a request param instead.

Work around:

You could change the RequestMapping to

@RequestMapping(value = "/ws/stuff/lookup/resourceId/**", method = RequestMethod.GET) 

and then parse the path variables manually from the request object.

这篇关于使用Spring RequestMapping path param编码的斜杠(%2F)给出了HTTP 400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆