我试图下载一个小型zip文件,Ruby RestClient库超级慢。通过浏览器下载需要<1秒。但是Ruby需要几分钟。
为什么会这样?
示例:
require 'rest-client'
RestClient.get("http://prd-enforce-xfr-02.dol.gov/data_catalog/OSHA/osha_accident_abstract_20161013.csv.zip")
答案 0 :(得分:0)
我认为该服务器的IPv6 AAAA记录已损坏。
prd-enforce-xfr-02.dol.gov has address 63.106.133.229
prd-enforce-xfr-02.dol.gov has IPv6 address 2607:f250:d008:2029:63:106:133:129
我无法通过IPv6连接到服务器。使用wget下载,在超时后它会回退到IPv4。
$ wget --timeout=20 http://prd-enforce-xfr-02.dol.gov/data_catalog/OSHA/osha_accident_abstract_20161019.csv.zip
--2016-10-19 22:40:24-- http://prd-enforce-xfr-02.dol.gov/data_catalog/OSHA/osha_accident_abstract_20161019.csv.zip
Resolving prd-enforce-xfr-02.dol.gov (prd-enforce-xfr-02.dol.gov)... 2607:f250:d008:2029:63:106:133:129, 63.106.133.229
Connecting to prd-enforce-xfr-02.dol.gov (prd-enforce-xfr-02.dol.gov)|2607:f250:d008:2029:63:106:133:129|:80... failed: Connection timed out.
Connecting to prd-enforce-xfr-02.dol.gov (prd-enforce-xfr-02.dol.gov)|63.106.133.229|:80... connected.
HTTP request sent, awaiting response... 200 OK
在rest-client的引擎下,Ruby Net :: HTTP可能正在进行类似的超时。我认为浏览器在快速回退方面要聪明得多。不幸的是,我不确定在rest-client中是否有办法禁用IPv6。
使用原始Net :: HTTP,您可以将local_host
设置为本地IPv4地址以强制使用IPv4。