ReqwestでHTTP Requestのheaderを設定する方法
RequestBuilder(post()
やget()
の戻り値)のheaderメソッドに設定すればいいだけなのだけど,
RequestBuilder::header()
はkeyとvalueを要求する.
https://docs.rs/reqwest/0.10.8/reqwest/struct.RequestBuilder.html#method.header
このkeyになる値はreqwest::header::*
に定数として定義されてる.
https://docs.rs/reqwest/0.10.8/reqwest/header/index.html#constants
例
use reqwest;
let req_body = format!("{{\"key\": {} }}", value);
let client = reqwest::blocking::Client::new();
let resp = client::post("http://hogehoge.com/")
.header(reqwest::header::CONTENT_TYPE, "application_json")
.body(req_body)
.send()?;