405 error when POSTing to ASMX using jQuery?

帅比萌擦擦* 提交于 2019-12-23 04:48:14

问题


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



来源:https://stackoverflow.com/questions/19596977/405-error-when-posting-to-asmx-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!