webapi 发布接口报405错误(angularjs2.0)

时间:2023-03-09 08:51:40
webapi 发布接口报405错误(angularjs2.0)

参考链接:http://www.cnblogs.com/shenbin/p/5680976.html

web访问接口报405错误,以前的jQuery访问方式访问接口没有问题。

但是换成angularjs2.0之后调用接口就报405错误,ajax调用没有问题。

查找资料之后找到解决方案:

原因是webapi 默认的web.config有配置
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
有这么个配置,导致不行。要把他删掉,还要加上
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="POST,GET" />
<add name="Access-Control-Allow-Headers" value="x-requested-with,content-type,authorization,mypara,username" />
</customHeaders>
</httpProtocol>