我想从Ruby 1.9.2打开一个URL

我想从Ruby 1.9.2打开一个URL,ruby,stripe-payments,Ruby,Stripe Payments,如何从ruby 1.9.2打开此url curl https://api.stripe.com/v1/customers/[customer number]/subscriptions -u sk_test.... -d plan=5555 我从控制台打开了那个url。我使用了curl[url],没有任何问题 谢谢您可以使用Ruby的库,这是一个相当低级的库,也可以使用类似gem的库 编辑 不幸的是,它不发送帖子,所以您不能指定什么是--datacurl选项。但是,您可以使用基本http身份验

如何从ruby 1.9.2打开此url

curl https://api.stripe.com/v1/customers/[customer number]/subscriptions -u sk_test.... -d plan=5555
我从控制台打开了那个url。我使用了
curl[url]
,没有任何问题

谢谢

您可以使用Ruby的库,这是一个相当低级的库,也可以使用类似gem的库

编辑

不幸的是,它不发送帖子,所以您不能指定什么是
--data
curl选项。但是,您可以使用基本http身份验证: 身份验证(相当于curl-u):


我会这样做:

# Attributes you have to set
basic_auth_credentials = ['sk_test', 'password']
customer_number = 1234
data = { 'plan' => '5555' }

# Build and parse the URL
uri  = URI("https://api.stripe.com/v1/customers/#{customer_number}/subscriptions")

# Build the POST request
request = Net::HTTP::Post.new(uri)

# Add form data to the POST request
request.set_form_data(data)

# Authenticate with http basic auth
request.basic_auth(*basic_auth_credentials)

# Build HTTP and set options to use HTTPS/SSL
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

# You might consider using `OpenSSL::SSL::VERIFY_PEER` on production
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

# Finally do the request
response = http.request(request)

你试了什么?你有什么问题?你的问题是什么?你好,斯皮克曼。我想从Ruby代码中打开url,我尝试使用OpenURI,但我不知道如何将这部分
-u sk_test-d plan=5555
如果我把它全部像curl一样放,我会得到“Url不正确”这是你不想使用Stripe的Ruby API库的原因吗?我正在为sprite使用gem,但它很旧,没有订阅的方法,我想使用curl调用。谢谢brito,我有一个问题。如何添加-u[token]和-d plan=[plan]?因为如果我像这样放网址:谢谢brito,我有一个问题。如何添加-u[token]和-d plan=[plan]?因为如果我把这部分
-u toke-d计划和所有URL放在一起,我会得到错误。url不正确。
open("http://www.ruby-lang.org/",  :http_basic_authentication=>[user, password]) {|f|
 ...
}
# Attributes you have to set
basic_auth_credentials = ['sk_test', 'password']
customer_number = 1234
data = { 'plan' => '5555' }

# Build and parse the URL
uri  = URI("https://api.stripe.com/v1/customers/#{customer_number}/subscriptions")

# Build the POST request
request = Net::HTTP::Post.new(uri)

# Add form data to the POST request
request.set_form_data(data)

# Authenticate with http basic auth
request.basic_auth(*basic_auth_credentials)

# Build HTTP and set options to use HTTPS/SSL
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

# You might consider using `OpenSSL::SSL::VERIFY_PEER` on production
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

# Finally do the request
response = http.request(request)