1
我提出一個要求,並出現以下Ruby腳本的響應:的Net :: HTTP ::獲取到RestClient.get
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://somesite.com/api/advisors/2050212?api_key=some_key&username=some_username)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["cache-control"] = 'no-cache'
request["token"] = 'token'
response = http.request(request)
puts response.read_body
使用RestClient我建立了以下內容:
resource = RestClient::Resource.new 'https://somesite.com/api/advisors', {params: {id: 2050212, api_key: 'some_key', username: 'some_username' }}
resource.get
我得到這個迴應:
RestClient::Unauthorized: 401 Unauthorized
from /Users/user/.rvm/gems/ruby-2.3.1/gems/rest-client-1.8.0/lib/restclient/abstract_response.rb:74:in `return!'
第一次在RestClient中進行遊戲。我如何構建選項散列?
這意味着你被拒絕,因爲可能有某種類型的訪問控制機制阻止你。您的請求沒有任何不妥之處。 – tadman