本文简要介绍ruby语言中 Net::HTTP.get
的用法。
用法
get(path, initheader = nil, dest = nil) { |body_segment| ... }
从 connected-to 主机上的 path
检索数据,这可能是要从中提取路径的绝对路径 String
或 URI
。
initheader
必须是 Hash
,例如 { ‘Accept’ => ‘/’, ... },并且默认为空哈希。如果 initheader
没有键 'accept-encoding',则使用值“gzip;q=1.0,deflate;q=0.6,identity;q=0.3”,因此优先使用 gzip 压缩放气压缩,优先使用无压缩。 Ruby 没有支持 compress (Lempel-Ziv) 压缩的库,因此不支持。这样做的目的是在默认情况下减少带宽。如果此例程设置了压缩,那么它也会进行解压缩,同时删除标头以防止混淆。否则,它会像找到它一样离开身体。
此方法返回一个 Net::HTTPResponse
对象。
如果使用块调用,则在从套接字读取时依次将实体主体的每个片段生成为字符串。请注意,在这种情况下,返回的响应对象将不包含(有意义的)正文。
dest
参数已过时。它仍然有效,但您不能使用它。
此方法从不引发异常。
response = http.get('/index.html')
# using block
File.open('result.txt', 'w') {|f|
http.get('/~foo/') do |str|
f.write str
end
}
相关用法
- Ruby HTTP.get用法及代码示例
- Ruby HTTP.get_print用法及代码示例
- Ruby HTTP.get_response用法及代码示例
- Ruby HTTP.request_head用法及代码示例
- Ruby HTTP.origin用法及代码示例
- Ruby HTTP.set_debug_output用法及代码示例
- Ruby HTTP.request_uri用法及代码示例
- Ruby HTTP.post_form用法及代码示例
- Ruby HTTP.request_post用法及代码示例
- Ruby HTTP.send_request用法及代码示例
- Ruby HTTP.request_get用法及代码示例
- Ruby HTTP.head用法及代码示例
- Ruby HTTP.post用法及代码示例
- Ruby HTTP.authority用法及代码示例
- Ruby HTTP.build用法及代码示例
- Ruby HTTPResponse类用法及代码示例
- Ruby HTTPHeader.to_hash用法及代码示例
- Ruby HTTPHeader.add_field用法及代码示例
- Ruby HTTPHeader.each_header用法及代码示例
- Ruby HTTPResponse.read_body用法及代码示例
- Ruby HTTPHeader.set_form_data用法及代码示例
- Ruby HTTPHeader.get_fields用法及代码示例
- Ruby HTTPHeader.set_form用法及代码示例
- Ruby HTTPResponse.body用法及代码示例
- Ruby HTTP类用法及代码示例
注:本文由纯净天空筛选整理自ruby-lang.org大神的英文原创作品 HTTP.get。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。