我正在尝试使用模型文件中的after_create
回调将发布请求发送到本地的其他应用程序。
接收错误为#
require 'net/http'
def request_details
uri = URI('http://localhost:4000/api/v1/requests/new')
http = Net::HTTP.new(uri.host, uri.port)
req = Net::HTTP::Post.new(uri.path, {'Content-Type' => 'application/json'})
req.body = {data1: self.data1, data2: self.data2,data3: self.data3,data4: self.data4}.to_json
response = http.request(req)
end
当我在另一个应用程序的日志中获取此信息时:
Started POST "/api/v1/requests/new" for 127.0.0.1 at 2018-12-29 01:20:43 +0530
SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
有人可以在这里解决问题吗?
答案 0 :(得分:0)
我建议您使用REST Client宝石。
function handleTouch(e) {
e.preventDefault();
}
document.getElementsByClassName("hoverable").addEventListener('touchstart', handleTouch, false);
document.getElementsByClassName("hoverable").removeEventListener('touchstart', handleTouch);
gem install rest-client
require 'rest-client'
RestClient.post(url, payload, headers={})