我想通过RestClient ruby API将JSON数据发送到Sinatra应用程序。使用RestClient和Sinatra发送和接收JSON
在客户端(client.rb)(使用RESTClient实现API)
response = RestClient.post 'http://localhost:4567/solve', jdata, :content_type => :json, :accept => :json
在服务器(西纳特拉)
require "rubygems"
require "sinatra"
post '/solve/:data' do
jdata = params[:data]
for_json = JSON.parse(jdata)
end
我收到以下错误
/Library/Ruby/Gems/1.8/gems/rest-client-1.5.1/lib/restclient/abstract_response.rb:53:in `return!': Resource Not Found (RestClient::ResourceNotFound)
from /Library/Ruby/Gems/1.8/gems/rest-client-1.5.1/lib/restclient/request.rb:193:in `process_result'
from /Library/Ruby/Gems/1.8/gems/rest-client-1.5.1/lib/restclient/request.rb:142:in `transmit'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:543:in `start'
from /Library/Ruby/Gems/1.8/gems/rest-client-1.5.1/lib/restclient/request.rb:139:in `transmit'
from /Library/Ruby/Gems/1.8/gems/rest-client-1.5.1/lib/restclient/request.rb:56:in `execute'
from /Library/Ruby/Gems/1.8/gems/rest-client-1.5.1/lib/restclient/request.rb:31:in `execute'
from /Library/Ruby/Gems/1.8/gems/rest-client-1.5.1/lib/restclient.rb:72:in `post'
from client.rb:52
所有我想要的是发送JSON数据并使用RestClient和Sinatra接收JSON数据。但无论我尝试什么,我都会收到上述错误。我坚持了3个小时。请帮助
我用你的代码做了。但我仍然得到这个概率 – Anand 2010-06-08 12:39:00
我没有重新启动我的sintara服务器..多数民众赞成的概率..;)你的代码工作像甜 – Anand 2010-06-08 13:57:09