3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Rust] ReqwestでHTTP Requestのheaderを設定する

Posted at

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()?;
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?