【问题标题】:Lumen POST Issue流明 POST 问题
【发布时间】:2018-08-10 18:35:46
【问题描述】:

我正在使用 Laravel Lumen 设置快速 REST 服务。我非常简单的路线列表:

$router->group(['prefix' => 'v1', function() use ($router){
    $router->get('status', function(){
        return  "ready";
    });

    $router->post('reading', function(){
        return "Hello";
    });
});

我安装了https://github.com/appzcoder/lumen-route-list,当我运行它时,我看到了我的两条路线。当我从客户端(通过 C)发出 POST 时,即:

   #define POST_THING  "POST /v1/reading HTTP/1.1\r\n"\
                       "Accept: */*\r\n"\
                       "Refer: exampledomain.ca\r\n"\
                       "Accept-Language: */*\r\n"\
                       "Content-Type: application/x-www-form-urlencoded\r\n"\
                       "Accept-Encoding: */*\r\n"\
                       "User-Agent: Mozilla/5.0\r\n"\
                       "Pragma: no-cache\r\n"\
                       "Connection: keep-alive\r\n"\
                       "key=101abc\r\n"\
                       "Content-Length: 11\r\n"\
                       "\r\n"

我得到一个 400:

[02/Mar/2018:08:51:43 -0500] "POST /v1/reading HTTP/1.1" 400 3170 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like壁虎)Chrome/64.0.3282.186 Safari/537.36"

我从我的客户那里得到:

400 错误请求

Bad Request 您的浏览器发送了此服务器无法发送的请求 明白。(缩短)

GET 路由工作正常,我“准备好了”,在我尝试执行 POST 之前,我做错了什么吗?

谢谢 D

【问题讨论】:

  • 你真的发送了你在标题Content-Length中指定的11字节内容吗?

标签: php post lumen


【解决方案1】:

解决了我的问题!我将 POST 更改为:

   #define POST_THING  "POST /v1/reading HTTP/1.1\r\n"\
                       "Accept: */*\r\n"\
                       "Refer: exampledomain.ca\r\n"\
                       "Accept-Language: */*\r\n"\
                       "Content-Type: application/x-www-form-urlencoded\r\n"\
                       "Accept-Encoding: */*\r\n"\
                       "User-Agent: Mozilla/5.0\r\n"\
                       "Pragma: no-cache\r\n"\
                       "Connection: keep-alive\r\n"\
                       "Content-Length: 10\r\n"\
                       "\r\n"\
                       "key=101abc\r\n"

现在它工作正常!希望这可以帮助其他遇到同样问题的人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-06
    • 2020-06-05
    • 2021-03-16
    • 2015-07-03
    • 2016-07-14
    • 2015-01-15
    • 2018-09-14
    • 2010-10-16
    相关资源
    最近更新 更多