You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 8 POST API传带属性HTML标签时返回405方法不允许问题

Laravel 8 API在共享主机返回405 Method Not Allowed,本地测试正常(含HTML标签属性时触发)

我用Laravel 8开发了一个接收含HTML元素负载的POST API,本地服务器用Postman测试时能正常返回200状态码,但部署到共享主机后,当请求负载的content字段包含带属性的HTML标签时,接口返回405 Method Not Allowed;如果去掉HTML标签的属性引号(比如把<p style="color: rgb(0,0,0);">改成<p>),接口就能正常返回200。


控制器代码(QuestionController)

class QuestionController extends Controller {

    public function storeQuestion(Request $request) {
        // 这里做一些验证逻辑
        
        $datas = $request['datas'];
        foreach($datas as $question):
            $newQuestion = new TbQuestion;
            $newQuestion->name = $question->name;

            // 这里是带HTML标签的content字段
            $newQuestion->content = $question->content;
            $newQuestion->save();
        endforeach;
    }

}

路由配置

<?php

$router->group(['middleware' => 'auth'], function() use ($router) {
    $router->post('/input/question', [
        'uses' => 'QuestionController@storeQuestion'
    ]);
});

触发405的测试请求数据

datas[0][name] = "Question number 1"
datas[0][content]  = <p style="color: rgb(0,0,0);">What the meaning of question?</p>

可正常请求的数据

datas[0][name] = "Question number 1"
datas[0][content] = <p>What the meaning of question?</p>

已尝试的无效方案

  • 替换共享主机上应用的vendor文件夹,无效果;
  • 目前仅能通过移除HTML标签属性解决问题,但这不符合软件需求。

想了解该问题的根本原因,以及无需移除HTML属性的解决方法。

内容的提问来源于stack exchange,提问作者Ikhsan Hamidan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 11:07:40