我在使用 ruby 获取 HTTP Put 调用中传递的参数时遇到问题。看一下“put_data”变量。当我将其保留为哈希时,ruby 说:
undefined method `bytesize' for #<Hash:0x007fbf41a109e8>
如果我转换为字符串,我会得到:
can't convert Net::HTTPUnauthorized into String
我也试过做 - '?token=wBsB16NSrfVDpZPoEpM'
def process_activation
uri = URI("http://localhost:3000/api/v1/activation/" + self.member_card_num)
Net::HTTP.start(uri.host, uri.port) do |http|
headers = {'Content-Type' => 'text/plain; charset=utf-8'}
put_data = {:token => "wBsB16NSrfVDpZPoEpM"}
response = http.send_request('PUT', uri.request_uri, put_data, headers)
result = JSON.parse(response)
end
if result['card']['state']['state'] == "active"
return true
else
return false
end
end
我到处搜索,包括 rubydocs,但找不到如何编码参数的示例。任何帮助,将不胜感激。