【发布时间】:2014-10-10 03:29:16
【问题描述】:
我能够从 AngularJS 成功 POST 到我的 Sinatra 路由,这样我就获得了“200”状态。
当我在 Chrome 中检查时,我看到请求负载如下:
{"input":"testing"}
但是响应是空的。
我是这样发布的:
$http({
method: "POST",
url: "http://floating-beyond-3787.herokuapp.com/angular",
/*url: "https://worker-aws-us-east-1.iron.io/2/projects/542c8609827e3f0005000123/tasks/webhook?code_name=botweb&oauth=LOo5Nc0x0e2GJ838_nbKoheXqM0",*/
data: {input: $scope.newChat}
})
.success(function (data)
{
// $scope.chats.push(data);
$scope.chats.push($scope.newChat)
// if successful then get the value from the cache?
})
.error(function (data)
{
$scope.errors.push(data);
});
};
$scope.newChat = null
请求有效负载下的 Chrome 显示正确 - 如上所述。
当我在运行 Sinatra 应用程序的 Heroku 中检查日志时,我无法判断我是否正确处理了请求负载。而且我肯定没有在响应中得到任何东西:
post '/angular' do
puts "params: #{params}"
puts params[:input]
puts @json = JSON.parse(request.body.read)
return RestClient.post 'https://worker.io' {:send => params[:input]}
end
我的期望是:
- Sinatra 应用可以接收负载:输入
- 它可以在 Iron.io 上成功发布给我的工作人员
- 它可以在对 Angular JS 的响应中返回一些内容以及 Success。
这可能吗?如果可以,怎么做?
【问题讨论】:
标签: ruby angularjs heroku sinatra