首页 > 解决方案 > Laravel:通过 Axios 在 Azure 上为 DELETE 请求获取 405

问题描述

我已经在 Laravel 项目上工作了一段时间,不幸的是,在 Microsoft Azure 上托管的生产版本上发送 DELETE 请求时遇到了障碍。我发现问题是 Azure 默认拒绝我被定向到的 DELETE 请求:如何在 Azure 中启用 PUT 请求?. 但是,我已将 web.config 文件更新为以下内容:(服务器 PHP 版本 7.3,64 位)

<configuration>
  <system.web>
    <customErrors mode="Off"/>
  </system.web>
  <system.webServer>
    <handlers>
      <remove name="PHP73_via_FastCGI" />
      <add name="PHP73_via_FastCGI" path="*.php" verb="GET, PUT, POST, HEAD, OPTIONS, TRACE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, DELETE" modules="FastCgiModule" scriptProcessor="D:\Program Files\PHP\v7.3\php-cgi.exe" resourceType="Either" requireAccess="Script" />
    </handlers>
    <rewrite>
      <rules>
        <rule name="Imported Rule 1" stopProcessing="true">
          <match url="^(.*)/$" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="/{R:1}" />
        </rule>
        <rule name="Imported Rule 2" stopProcessing="true">
          <match url="^" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

我之前曾尝试运行此访问D:\Program Files (x86),但不幸的是,这也没有奏效。我已经发布了整个 web.config,因为我不确定添加的其他一些设置是否与尝试启用 DELETE 冲突。

作为参考,这里的路线被称为:

Route::group(['middleware' => ['auth']], function($router) {
    Route::post('likes', 'LikesController@store');
    Route::delete('likes/{', 'LikesController@remove');
    Route::delete('likes/{like}', 'LikesController@remove');
});

调用LikesController@remove仅运行$like->delete();,然后返回没有已删除的类似评论的评论。

视图组件内部调用 axios 的方法:

axios.post('/api/likes', {comment_id: this.comment.id}).then((response) => {
  this.comment = response.data;
}

我在本地构建上运行良好,所以我不确定为什么问题在提供的修复之外仍然存在。如果还有什么需要的,请告诉我,我会编辑帖子。

标签: laravelazure

解决方案


推荐阅读