首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对get和post的相同请求映射不适用于spring

对get和post的相同请求映射不适用于spring
EN

Stack Overflow用户
提问于 2017-08-28 09:28:48
回答 1查看 810关注 0票数 1

我使用spring编写了以下控制器。Request /webbroker/被映射到请求GET和POST.For,得到它的工作状态,但是对于POST,它的抛出低于错误。

不支持请求方法。

知道它为什么这样做吗?

代码语言:javascript
复制
@Controller
public class ProxyController {

    @Autowired
    private RequestHandler reqHandler;

    @Autowired
    private ResponseHandler responseHandler;


    @RequestMapping(value = "/webbroker/**", method = RequestMethod.GET)
    public void edgefxGetRequest(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
            throws IOException {        
        HttpURLConnection connection = this.reqHandler.handleRequest(httpRequest, httpResponse, false);
        this.responseHandler.sendResponse(connection, httpResponse);
    }

    @RequestMapping(value = "/webbroker/**", method = RequestMethod.POST)
    public void edgefxPostRequest(HttpServletRequest httpRequest,
            HttpServletResponse httpResponse) throws IOException, URISyntaxException {
        HttpURLConnection connection = this.reqHandler.handleRequest(httpRequest, httpResponse, true);
        this.responseHandler.sendResponse(connection, httpResponse);
    }

    @RequestMapping(value = "/webbroker-strong/**", method = RequestMethod.GET)
    public void edgefxStrongGetRequest(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
            throws IOException {        
        HttpURLConnection connection = this.reqHandler.handleRequest( httpRequest, httpResponse, false);
        this.responseHandler.sendResponse(connection, httpResponse);
    }

    @RequestMapping(value = "/webbroker-strong/**", method = RequestMethod.POST)
    public void edgefxStrongPostRequest(HttpServletRequest httpRequest,
            HttpServletResponse httpResponse) throws IOException, URISyntaxException {
        HttpURLConnection connection = this.reqHandler.handleRequest(httpRequest, httpResponse, true);
        this.responseHandler.sendResponse(connection, httpResponse);
    }
}
EN

回答 1

Stack Overflow用户

发布于 2017-08-28 09:34:42

试试这个:

代码语言:javascript
复制
@RequestMapping(value = "/webbroker/**", method = { RequestMethod.GET, RequestMethod.POST })
public void edgefxRequest(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
        throws IOException {        
    HttpURLConnection connection = this.reqHandler.handleRequest(httpRequest, httpResponse, false);
    this.responseHandler.sendResponse(connection, httpResponse);
}

您不需要为两个HTTP方法复制处理程序方法。只需将method参数声明为数组即可。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45915828

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档