ruby-on-rails – 使用net / http发送Post请求
发布时间:2020-12-16 19:52:37 所属栏目:百科 来源:网络整理
导读:我需要将 JSON中的数据发送到在同一台计算机上运行的另一个应用程序. 我发出这样的请求(rails 3.2.13) data = { //some data hash } url = URI.parse('http://localhost:6379/api/plans') resp,data = Net::HTTP.post_form(url,data.to_JSON ) p resp p data
我需要将
JSON中的数据发送到在同一台计算机上运行的另一个应用程序.
我发出这样的请求(rails 3.2.13) data = { //some data hash } url = URI.parse('http://localhost:6379/api/plans') resp,data = Net::HTTP.post_form(url,data.to_JSON ) p resp p data { resp: resp,data: data.to_JSON } 但是我得到了Net :: HTTPBadResponse(错误的状态行:“-ERR unknown command’POST’”): 更新1 url = URI.parse('http://localhost:6379/v1/sessions') http = Net::HTTP.new(url.host,url.port) http.use_ssl = true resp,data) p resp p data 但是我仍然收到错误Net :: HTTPBadResponse(错误的状态行:“-ERR未知命令’POST’”): 解决方法
我不知道你的问题是什么,但是这样的东西呢
http = Net::HTTP.new(uri.host,uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.path,{'Content-Type' => 'application/json'}) request.body = data.to_json response = http.request(request) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |