我正在尝试使用Ruby与一个网站的API进行交互。网站给出的指示是发送一个带有header的GET请求,并提供了以下PHP代码示例。我需要计算一个HMAC哈希并将其包含在apisign
头中。
$apikey='xxx';
$apisecret='xxx';
$nonce=time();
$uri='https://bittrex.com/api/v1.1/market/getopenorders?apikey='.$apikey.'&nonce='.$nonce;
$sign=hash_hmac('sha512',$uri,$apisecret);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult = curl_exec($ch);
$obj = json_decode($execResult);
我只是在Windows的命令提示符中使用带有Ruby安装的.rb文件。 我在Ruby文件中使用net/http。 如何发送带有标头的GET请求并打印响应?
URI("https://www.google.com/search?q=what+is+my+user+agent")
,那么程序就无法工作,并显示错误信息end of file reached (EOFError)
。我认为这是由于 URL 中的https
导致的。这个程序能否适用于任何 URL? - nonopolarityNet::HTTP.start
改为Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https')
。 - nonopolarity