參考鏈接:http://www.cnblogs.com/shenbin/p/5680976.html web訪問介面報405錯誤,以前的jQuery訪問方式訪問介面沒有問題。 但是換成angularjs2.0之後調用介面就報405錯誤,ajax調用沒有問題。 查找資料之後找到解決方案: 原因是web ...
參考鏈接: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>