我正在try 从澳大利亚统计局下载一个带有Rust的压缩文件.
下面的python代码运行得很好.
import requests
def example():
url = (
"http://www.abs.gov.au/statistics/economy/price-indexes-and-inflation/"
"monthly-consumer-price-index-indicator/dec-2023/All-Time-Series-Spreadsheets.zip"
)
response = requests.get(url, allow_redirects=True, stream=True, timeout=20)
if response.status_code == 200 and response.headers is not None:
size = sum(len(chunk) for chunk in response.iter_content(8196))
print(size)
example() # prints 127525 (bytes)
然而,当我在Rust中try 类似的东西时(我已经try 了几个不同的 crate ),我无法让它工作.示例代码如下.
fn example() {
let url = concat!(
"http://www.abs.gov.au/statistics/economy/price-indexes-and-inflation/",
"monthly-consumer-price-index-indicator/dec-2023/All-Time-Series-Spreadsheets.zip"
);
let client = reqwest::blocking::Client::new();
let zip_bytes = client
.get(url)
.send().unwrap()
.bytes().unwrap();
println!("Length: {}", zip_bytes.len());
}
example() // prints 70