我試圖從本教程學習一些紅寶石HTTP請求響應代碼 -語法錯誤 - 意外tASSOC
http://danknox.github.io/2013/01/27/using-rubys-native-nethttp-library/
到目前爲止的代碼 -
require "net/http"
require "uri"
uri = URI.parse("http://api.random.com")
http = Net::HTTP.new(uri.host, uri.port)
# Continuing our example from above
request = Net::HTTP::Get.new("/search?question=somequestion")
response = http.request(request)
response.code
=>"200"
response.body
=> # Raw response body would go here needing to be parsed
錯誤 -
Test.rb:13: syntax error, unexpected tASSOC, expecting $end
=> "200"
^
我不知道爲什麼會發生這種情況。我刪除了空間,錯誤依然存在。我看到3-4堆棧溢出帖子,但他們沒有幫助。
什麼是'=>「200」?它看起來像是從irb上剪切粘貼的東西。編輯:啊,從鏈接文章來看,似乎是這樣,儘管作者沒有說清楚。 – 2014-12-04 21:10:09