无法使用 Curl 在 Sinatra 中接受帖子

OVE*_*ONE 2 ruby rest post curl sinatra

刚刚修改了 Sinatra 并试图让一个安静的网络服务运行起来。不过,我目前遇到的错误非常具体。

拿这个例子post方法

post '/postMan/:someParam' do
    #Edited here. This code can be anything. 411 is still the response
    puts params[:someParam]

end
Run Code Online (Sandbox Code Playgroud)

看起来很简单。获取一个参数,从中创建一个对象,然后以对象保存方法定义的任何方式存储它。

这是我用来使用 Curl 发布数据的内容

$curl -I -X POST http://127.0.0.1/postman/123456
Run Code Online (Sandbox Code Playgroud)

唯一的问题是,我收到了 411,但不知道为什么。据我所知,411 是必需的长度。这是踪迹

HTTP/1.1 411 Length Required 
Content-Type: text/html; charset=ISO-8859-1
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
Date: Fri, 02 Mar 2012 22:27:09 GMT
Content-Length: 303
Connection: close
Run Code Online (Sandbox Code Playgroud)

我“无法”以任何方式更改 curl 消息。那么可能有人有办法在 sinatra 中设置要忽略的内容长度吗?或者一些不涉及更改 curl 请求的修复?


作为记录,我是否在 Post 方法中使用参数并不重要。我可以在里面有一些疯狂的代码,它仍然会抛出同样的错误

Asf*_*azi 5

正如上面其他人所说,WEBrick 错误地要求 POST 请求具有 Content-Length 标头。我只是传递一个空的正文,因为它比传递标题要少打字:

curl -X POST -d '' http://webrickwhyyounotakeemptyposts.com/
Run Code Online (Sandbox Code Playgroud)