# Assume @user_name and @password were previously declared to be the
# appropriate basic auth values and that the connection is open as @connection
def put(path, body, header={})
request = Net::HTTP::Put.new(path, header.merge({'Accept' => 'application/xml,application/json', 'Content-type'=>'application/json'}))
request.basic_auth(@user_name, @password)
@connection.request(request, body).body
end
def post(path, body, header={})
request = Net::HTTP::Post.new(path, header.merge({'Accept' => 'application/xml,application/json', 'Content-type'=>'application/json'}))
request.basic_auth(@user_name, @password)
@connection.request(request, body).body
end
def get(path, header={})
request = Net::HTTP::Get.new(path)
request.basic_auth(@user_name, @password)
@connection.request(request).body
end
然后,我对这些方法的输出调用了JSON::parse(),得到了一个表示JSON的哈希,我认为可以使用它。