File tree Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 6565 - [ Making Requests] ( web/clients/requests.md )
6666 - [ Calling a Web API] ( web/clients/apis.md )
6767 - [ Downloads] ( web/clients/download.md )
68+ - [ Web Authentication] ( web/clients/authentication.md )
Original file line number Diff line number Diff line change 3939| [ Make a partial download with HTTP range headers] [ ex-progress-with-range ] | [ ![ reqwest-badge]] [ reqwest ] | [ ![ cat-net-badge]] [ cat-net ] |
4040| [ POST a file to paste-rs] [ ex-file-post ] | [ ![ reqwest-badge]] [ reqwest ] | [ ![ cat-net-badge]] [ cat-net ] |
4141
42+ ## Web Authentication
43+
44+ | Recipe | Crates | Categories |
45+ | --------| --------| ------------|
46+ | [ Basic Authentication] [ ex-basic-authentication ] | [ ![ reqwest-badge]] [ reqwest ] | [ ![ cat-net-badge]] [ cat-net ] |
47+
4248[ ex-extract-links-webpage ] : web/scraping.html#extract-all-links-from-a-webpage-html
4349[ ex-check-broken-links ] : web/scraping.html#check-a-webpage-for-broken-links
4450[ ex-extract-mediawiki-links ] : web/scraping.html#extract-all-unique-links-from-a-mediawiki-markup
6470[ ex-progress-with-range ] : web/clients/download.html#make-a-partial-download-with-http-range-headers
6571[ ex-file-post ] : web/clients/download.html#post-a-file-to-paste-rs
6672
73+ [ ex-basic-authentication ] : web/clients/authentication.html#basic-authentication
74+
6775{{#include links.md}}
Original file line number Diff line number Diff line change 1+ # Authentication
2+
3+ {{#include authentication/basic.md}}
4+
5+ {{#include ../../links.md}}
Original file line number Diff line number Diff line change 1+ ## Basic Authentication
2+
3+ [ ![ reqwest-badge]] [ reqwest ] [ ![ cat-net-badge]] [ cat-net ]
4+
5+ Uses [ ` reqwest::RequestBuilder::basic_auth ` ] to perform a basic HTTP authentication.
6+
7+ ``` rust,edition2018,no_run
8+ use reqwest::blocking::Client;
9+ use reqwest::Error;
10+
11+ fn main() -> Result<(), Error> {
12+ let client = Client::new();
13+
14+ let user_name = "testuser".to_string();
15+ let password: Option<String> = None;
16+
17+ let response = client
18+ .get("https://httpbin.org/")
19+ .basic_auth(user_name, password)
20+ .send();
21+
22+ println!("{:?}", response);
23+
24+ Ok(())
25+ }
26+ ```
27+
28+ [ `reqwest::RequestBuilder::basic_auth` ] : https://docs.rs/reqwest/*/reqwest/struct.RequestBuilder.html#method.basic_auth
You can’t perform that action at this time.
0 commit comments