我正在与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 Gecko)Chrome / 64.0.3282.186 Safari / 537.36“
从我的客户那里得到:
400错误请求
错误请求您的浏览器发送了此服务器无法发出的请求 理解。(缩短)
GET路线工作正常,我准备好了,在我尝试执行POST之前,我做错了什么?
由于 d
答案 0 :(得分:0)
弄明白我的问题!我将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"
现在它运作正常!希望这有助于其他人遇到同样的问题。