【问题标题】:HTTP Status 405 - Request method 'POST' not supported Spring MVCHTTP 状态 405 - Spring MVC 不支持请求方法“POST”
【发布时间】:2014-09-24 21:16:14
【问题描述】:

场景是用户选择一些产品,然后点击付款。在这里,我将他/她重定向到 IPG(银行的互联网支付网关),并在付款完成时传递我的返回 URL 并完成采购订单。在我添加弹簧安全之前,一切正常。

但如果在某些内部视图中发布此网址,一切都会再次正常工作。

这很好(弹簧安全启用,一切正常)

<form:form method="post" name="saleform" id="saleform"
    action="http://localhost:8080/Click2Pay/salecomplete">
    <input class="btn btn-primary" type="submit" value=" SaleComplete "
        id="btnsalecomplete" name="btnsalecomplete" />

</form:form>


    @RequestMapping(value = "/salecomplete", method = RequestMethod.POST)
        public String salecomplete(HttpServletRequest request,
                HttpServletResponse response, Model m)
                throws
<http auto-config="true" use-expressions="true">
        <intercept-url pattern="/admin/**" access="hasRole('admin')" />
        <access-denied-handler error-page="/403" />
        <form-login login-page="/login" default-target-url="/admin/admin"
            authentication-failure-url="/login?error" username-parameter="username"
            password-parameter="password" />
        <logout logout-success-url="/login?logout" />
        <!-- enable csrf protection -->
        <csrf />
    </http>



<authentication-manager>
        <authentication-provider user-service-ref="UserAuthenService">
            <password-encoder hash="sha" />
        </authentication-provider>
    </authentication-manager>

在浏览器中查看银行IPG的来源(https://pna.shaparak.ir/CardServices/paymentSuccess.html

<form action="http&#x3a;&#x2f;&#x2f;localhost&#x3a;8080&#x2f;Click2Pay&#x2f;salecomplete"
    method="post" autocomplete="off">
    <div class="commandBar">

            <input type="hidden" name="redirectURL" id="redirectURL"
                value="http&#x3a;&#x2f;&#x2f;localhost&#x3a;8080&#x2f;Click2Pay&#x2f;salecomplete" />

            <input type="hidden" name="MID" id="MID" value="01134254" />

            <input type="hidden" name="ResNum" id="ResNum" value="162" />

            <input type="hidden" name="RefNum" id="RefNum"
                value="00000000021278797788" /> <input type="hidden"
                name="CustomerRefNum" id="CustomerRefNum" value="421320082083" />


            <input type="hidden" name="State" id="State" value="OK" /> <input
                type="hidden" name="language" id="language" value="fa" /> <input
                type="hidden" name="CardPanHash" id="CardPanHash"
                value="417bf6657c3830d051b4e9bab45203508c386787d4c083244c4dbac82bd559b8" />
            <input type="submit" value="تکمیل خرید"
                class="button btn btn-success btn-lg" name="Submit" />

            <input type="button" value="لغو خرید"
                class="button btn btn-default btn-lg" name="cancelButton"
                id="cancelButton" onclick="document.forms['returnForm'].submit();" />

    </div>

    </form>

有什么问题?

【问题讨论】:

  • 可能是csrf保护。如果银行网站发回给您,这是跨站点请求,我看不到银行表格中的 csrf 令牌。尝试暂时禁用 csrf 保护。
  • 是的,这个问题。我在发布这个问题后的第二天找到它。如果你想发布你的答案。

标签: java spring spring-mvc spring-security


【解决方案1】:

如果银行网站回发到您的应用程序,那么这是跨站点请求,银行需要银行表格中不存在的 csrf 令牌。尝试暂时禁用 csrf 保护进行验证。

解决方案是:

  • 以某种方式将 CSRF 令牌传递给银行的表单
  • 通过为受 csrf 保护的 url 提供自定义请求匹配器来禁用该特定请求的 CSRF 保护:

    &lt;csrf request-matcher-ref="someRequestMatcher" /&gt;

  • 完全关闭 CSRF 保护(这会使其正常工作,但会使应用程序容易受到 CSRF 攻击)

【讨论】:

    猜你喜欢
    • 2012-06-24
    • 2015-04-09
    • 2016-03-29
    • 2013-04-09
    • 2012-04-20
    • 2013-11-25
    • 2015-05-01
    • 2020-07-24
    • 2015-01-31
    相关资源
    最近更新 更多