參考鏈接: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>
