我是 Rust 的新手,并试图使用reqwest
crate 调用 API。我希望我的代码;
- 在 GET 请求中包含“Content-Disposition: Inline”标头。
- 返回 JSON 并将其打印为文本
我不确定我做错了什么,希望有人可以帮助我识别它。
该请求在 JS 和 Postman 中对我来说很好,并返回数组 JSON 数据,也在我下面的 RUST 代码中请求返回 200 成功。
但是我看不到响应数据,远程服务器使用"Content-Disposition"
默认的标头响应(不是我指定的“内联”)。
我的 Rust 代码编译得很好,似乎可以发送:
extern crate reqwest;
use reqwest::header::HeaderName;
use reqwest::header::HeaderValue;
use reqwest::header::ACCEPT;
use reqwest::header::CONTENT_DISPOSITION;
fn main() {
let client = reqwest::Client::new();
let response_text = client
.get("http://nemlog.com.au/show/1h/NEMLOG.json?id1=RRP.DISPATCHPRICE0&k1=vic")
.header(CONTENT_DISPOSITION, "inline")
.header(ACCEPT, "*/*")
.send()
.unwrap();
println!("Response Text: {:#?}", response_text);
}
我从上述请求在控制台中收到的响应是:
Response Text: Response {
url: "http://nemlog.com.au/show/1h/NEMLOG.json?id1=RRP.DISPATCHPRICE0&k1=vic",
status: 200,
headers: {
"date": "Tue, 22 Oct 2019 06:33:45 GMT",
"server": "Apache/2.4.6 (CentOS) PHP/5.4.16 mod_wsgi/3.4 Python/2.7.5",
"content-disposition": "attachment; filename=NEMLOG.json",
"transfer-encoding": "chunked",
"content-type": "text/json; name=\"NEMLOG.json\"",
},
}
我希望看到的输出是来自调用的内联响应,如下所示:
{"SETTLEMENTDATE":"2019-10-22T10:45:00Z","REGIONID":"VIC1","RRP.DISPATCHPRICE0":91.272}
{"SETTLEMENTDATE":"2019-10-22T10:50:00Z","REGIONID":"VIC1","RRP.DISPATCHPRICE0":75.7859}
{"SETTLEMENTDATE":"2019-10-22T10:55:00Z","REGIONID":"VIC1","RRP.DISPATCHPRICE0":74.8683}
{"SETTLEMENTDATE":"2019-10-22T11:00:00Z","REGIONID":"VIC1","RRP.DISPATCHPRICE0":25.14}
{"SETTLEMENTDATE":"2019-10-22T11:05:00Z","REGIONID":"VIC1","RRP.DISPATCHPRICE0":16.4812}
{"SETTLEMENTDATE":"2019-10-22T11:10:00Z","REGIONID":"VIC1","RRP.DISPATCHPRICE0":56.4572}
{"SETTLEMENTDATE":"2019-10-22T11:15:00Z","REGIONID":"VIC1","RRP.DISPATCHPRICE0":38.5679}
{"SETTLEMENTDATE":"2019-10-22T11:20:00Z","REGIONID":"VIC1","RRP.DISPATCHPRICE0":47.5941}
{"SETTLEMENTDATE":"2019-10-22T11:25:00Z","REGIONID":"VIC1","RRP.DISPATCHPRICE0":25.14}
{"SETTLEMENTDATE":"2019-10-22T11:30:00Z","REGIONID":"VIC1","RRP.DISPATCHPRICE0":51.8465}
{"SETTLEMENTDATE":"2019-10-22T11:35:00Z","REGIONID":"VIC1","RRP.DISPATCHPRICE0":71.7957}
{"SETTLEMENTDATE":"2019-10-22T11:40:00Z","REGIONID":"VIC1","RRP.DISPATCHPRICE0":72.0757}