![](/img/trans.png)
[英]What is the equivalent code from urllib2 to urllib3 in python
[英]What is the equivalent ruby code for urllib2 in Python
我想傳遞網址,標題和query_params。 以下是python代碼。 我想用紅寶石做。 我上網沖浪,並且知道Net :: HTTP是執行此操作的正確方法。 但是此方法不接受查詢參數,並引發錯誤。 以下python代碼的ruby代碼等效於什么?
兩者都添加了文件下載鏈接
我也想在Ruby中獲得與python同樣的結果。
nonce=1404996712857&method=neworder&rate=1&order_type=buy&quantity=1 //post_data(query params)
headers = {'key': '1234567894444444', 'sign': 'jhjhgyyqw7y890190800iihuhugdhugabnmKOP'}
蟒蛇
url_request_object = urllib2.Request("%s/%s" % (BASE_API_URL,url_suffix),
post_data,
headers)
response = urllib2.urlopen(url_request_object)
紅寶石
response = Net::HTTP.post_form(uri, :body => post_data,:header => headers )
puts response.body
錯誤:
{"status": false, "message": "method required", "systime": 1404996498.0}
這應該可以幫助您。
require 'net/http'
html_request = Net::HTTP.new('site.com', 80)
path = '/path/where/form/is'
headers = {'Host' => 'site.com', 'Connection' => 'keep-alive', 'Key' => '1234567894444444', 'sign' => 'jhjhgyyqw7y890190800iihuhugdhugabnmKOP'}
post_data = 'nonce=1404996712857&method=neworder&rate=1&order_type=buy&quantity=1'
response = html_request.post(path, post_data, headers)
response_string = response.body.to_s
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.