Skip to content

Commit

Permalink
feat:update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ltpp-universe committed Dec 1, 2024
1 parent 10f2904 commit 090f2ee
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "http-request"
version = "5.1.0"
version = "5.2.0"
edition = "2021"
authors = ["ltpp-universe <[email protected]>"]
license = "MIT"
Expand Down
26 changes: 26 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,32 @@ _request_builder
.unwrap_or_else(|e| println!("error => {}", e));
```

#### Send Body Binary

```rs
use http_request::*;
use std::collections::HashMap;
let mut header: HashMap<&str, &str> = HashMap::new();
header.insert("header-key", "header-value");
let mut _request_builder = HttpRequestBuilder::new()
.post("http://localhost")
.body("hello".as_bytes())
.headers(header)
.timeout(6000)
.redirect()
.max_redirect_times(8)
.http1_1_only()
.buffer(4096)
.builder();
_request_builder
.send()
.and_then(|response| {
println!("{:?}", response.text());
Ok(())
})
.unwrap_or_else(|e| println!("error => {}", e));
```

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
Expand Down
28 changes: 28 additions & 0 deletions src/request/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,31 @@ fn test_http_post_text_request() {
})
.unwrap_or_else(|e| output("error => ", &format!("{:?}", e), Color::Red));
}

#[test]
fn test_http_post_binary_request() {
let mut header: HashMap<&str, &str> = HashMap::new();
header.insert("Accept", "*/*");
header.insert("Content-Type", "application/json");
let mut _request_builder = HttpRequestBuilder::new()
.post("http://localhost:80")
.body("hello".as_bytes())
.headers(header)
.timeout(6000)
.redirect()
.buffer(4096)
.max_redirect_times(8)
.http1_1_only()
.builder();
_request_builder
.send()
.and_then(|response| {
output(
"response => ",
&format!("{:?}", response.text()),
Color::Green,
);
Ok(())
})
.unwrap_or_else(|e| output("error => ", &format!("{:?}", e), Color::Red));
}

0 comments on commit 090f2ee

Please sign in to comment.