HTTP 错误 405.0 - 调用 API 时不允许使用方法

问题描述 投票:0回答:1

我有相同的 API,当在 Angular 2 中调用 API 时,我收到此错误:

HTTP 错误 405.0 - 方法不允许
由于使用了无效方法(HTTP 动词),因此无法显示您正在查找的页面。

我的网络配置:

<system.webServer>


    <rewrite>
      <!--This directive was not converted because it is not supported by IIS: RewriteBase /.-->
      <rules>
        <rule name="Imported Rule 1" stopProcessing="true">
          <match url="^index\.html" ignoreCase="false" />
          <action type="None" />
        </rule>
        <rule name="Imported Rule 2" stopProcessing="true">
          <match url="." ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.html" />
        </rule>
      </rules>
    </rewrite>
    
     <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="*" />
        <add name="Access-Control-Allow-Credentials" value="true" />
      </customHeaders>
    </httpProtocol>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="OPTIONSVerbHandler" />
      <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>
    <modules>
      <remove name="ApplicationInsightsWebTracking" />
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
    </modules>

如果删除网络配置中的规则标签,我的 API 可以工作,但是当刷新角度页面时,我收到此错误:

找不到资源。

angular2-routing
1个回答
0
投票

无论您选择哪种浏览器,都值得熟悉常用的 F12 开发人员工具,这些工具通常附带一些客户端可见性。

验证您的客户是否没有尝试做您不期望的事情非常有用,您可以看到动词、内容类型和可能帮助您跟踪它的 URL。

此外,您在配置中使用了 url 重写,因此服务器可能会在收到请求后调整您的请求,可能以您意想不到的方式 - 怀疑我需要更多有关相对 url 的信息未能提供更多建议。

例如,在 Chrome 中,您可以检查“网络”选项卡。

© www.soinside.com 2019 - 2024. All rights reserved.