python的等效ruby代码

时间:2014-07-11 11:49:23

标签: python ruby-on-rails ruby-on-rails-3 net-http

以下python代码的等效ruby代码是什么。我上网,发现net / http'是正确的方法。但我是ruby的新手,我无法有效地使用这种方法。任何人都可以帮我在python中写这个吗?

Python

url = "https://www.abcde.com/api/"
post_data = "method=a&rate=2&order=asc"
headers =  {"key"=>"55208252", "sign"=>"4589cab68921fb43ad53149ea625e29"}

url_request_object = urllib2.Request(url, post_data, headers)

response = urllib2.urlopen(url_request_object)

1 个答案:

答案 0 :(得分:1)

通讯方式的签名是相同的

http = Net::HTTP.new('localhost', 3000)
headers = {'Content-Type' =>  'application/json'}
data = {:test => 'test'}

resp, data = http.post(path, data.to_json, headers)