以下請求有什麼問題?Api請求與紅寶石Typhoeus
request = Typhoeus::Request.new("http://fluidsurveys.com/api/v2/groups",
method: :get,
userpwd: "test_user:test_password",
headers: { 'ContentType' => "application/json"})
response = request.body
puts response
這將返回undefined method body for #<Typhoeus::Request:0x007f8e50d3b1d0> (NoMethodError)
以下請求正常工作與httparty
:
call= "/api/v2/groups/"
auth = {:username => "test_user", :password => "test_password"}
url = HTTParty.get("http://fluidsurveys.com/api/v2/groups",
:basic_auth => auth,
:headers => { 'ContentType' => 'application/json' })
response = url.body
puts response
編輯:
我嘗試這樣做:
response = request.response
puts response.body
沒有運氣。我收到這個:undefined method body for nil:NilClass (NoMethodError)
該方法仍然返回錯誤。 – Luigi
它在上面的編輯中。 – Luigi
頭巴掌...好的,所以你必須得到一個響應,然後才能得到身體,當然。有沒有關於request.response的日誌消息?我期望響應方法返回一個哈希或HTTP錯誤的整數值,而不是零。此外,我要做一些研究,並會回來... –