gpt4 book ai didi

ruby-on-rails - 在 Ruby on Rails 上 curl

转载 作者:行者123 更新时间:2023-12-04 00:19:32 25 4
gpt4 key购买 nike

如何在rails上的ruby上使用curl?像这个

curl -d 'params1[name]=name&params2[email]' 'http://mydomain.com/file.json'

最佳答案

万一你不知道,它需要'net/http'

require 'net/http'

uri = URI.parse("http://example.org")

# Shortcut
#response = Net::HTTP.post_form(uri, {"user[name]" => "testusername", "user[email]" => "testemail@yahoo.com"})

# Full control
http = Net::HTTP.new(uri.host, uri.port)

request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data({"user[name]" => "testusername", "user[email]" => "testemail@yahoo.com"})

response = http.request(request)
render :json => response.body

希望它会帮助别人.. :)

关于ruby-on-rails - 在 Ruby on Rails 上 curl ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15804425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com