405 error when POSTing to ASMX using jQuery?

2019-06-13 16:13发布

问题:

Site is here.

Things we have tried:

  • ProtocolSupportModule has been updated to All verbs.

  • DNS is externally visible.

  • Anonymous Authentication is enabled.

  • Headers added:

    <customHeaders> <add name="Cache-Control" value="no-cache" /> <add name="Access-Control-Allow-Origin" value="http://s-alg.cengage .com" /> <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept, X-PINGOTHER" /> <add name="Access-Control-Allow-Methods" value="POST, GET, OPTIONS, HEAD" /> <add name="Access-Control-Max-Age" value="1000" /> </customHeaders>

I’m not sure what to try next. Hopefully is something to do with Web.config.

回答1:

The method has to be decorated with [WebInvoke] to enable POST method.

[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]

Update:

If it is asmx, include the below protocols in web.config

<webServices>
    <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
    </protocols>
</webServices>

in system.web

Also, decorate the web method with [scriptmethod] to be accessed from script