将POST调用发送到URL的最短方式?

时间:2012-01-30 03:58:03

标签: ruby-on-rails ruby-on-rails-3 http post

从Rails应用程序向外部URL发送POST调用的最短/最简单方法是什么?

我需要向这样的URL发送POST请求:

http://api.example.com/aff?id=12345&sub=123456

1 个答案:

答案 0 :(得分:2)

以下是一个很好的例子:How do I post XML to RESTFUL Web Service using Net::HTTP::Post?

url = URI.parse('http://api.example.com/aff?id=12345&sub=123456')
request = Net::HTTP::Post.new(url.path)
response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}