我试图从本教程学习一些红宝石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