使用Ruby和Calabash发出POST请求

时间:2012-11-22 15:05:21

标签: ruby post

我使用Calabsh来测试iOS应用。在测试期间,我需要创建POST请求以更改某些值,然后验证更改是否反映在UI中。

请求看起来像:

wwww.testserver.com/userAddMoney?user_id=1&amount=999

要在服务器上进行授权,我需要将特殊参数传递给请求的标头:

标题:X-Testing-Auth-Secret:kI7wGju76kjhJHGklk76

1 个答案:

答案 0 :(得分:1)

require 'net/http'

uri = URI.parse('http://www.testserver.com/userAddMoney?user_id=1&amount=999')
http = Net::HTTP.new(uri.host,uri.port)
##  https.use_ssl = true    # use https, need require net/https
req = Net::HTTP::Post.new(uri.path)
req['X-Testing-Auth-Secret'] = 'kI7wGju76kjhJHGklk76'
res = http.request(req)

此处的文档:Net::HTTP::Post Net::HTTPSession