1
0
mirror of synced 2025-04-28 09:25:05 +03:00

Updated README

This commit is contained in:
yhirose 2017-12-05 19:30:13 -05:00
parent bb8a1df7a3
commit d2982531bd

View File

@ -7,11 +7,11 @@ A C++11 header-only HTTP library.
It's extremely easy to setup. Just include **httplib.h** file in your code!
Inspired by [Sinatra](http://www.sinatrarb.com/) and [express](https://github.com/visionmedia/express).
Server Example
--------------
Inspired by [Sinatra](http://www.sinatrarb.com/) and [express](https://github.com/visionmedia/express).
```c++
#include <httplib.h>
@ -71,9 +71,24 @@ svr.set_error_handler([](const auto& req, auto& res) {
});
```
### `multipart/form-data` POST data
```cpp
svr.post("/multipart", [&](const auto& req, auto& res) {
auto size = req.files.size();
auto ret = req.has_file("name1"));
const auto& file = req.get_file_value("name1");
// file.filename;
// file.content_type;
auto body = req.body.substr(file.offset, file.length));
})
```
Client Example
--------------
### GET
```c++
#include <httplib.h>
#include <iostream>
@ -89,6 +104,22 @@ int main(void)
}
```
### POST
```c++
res = cli.post("/post", "text", "text/plain");
res = cli.post("/person", "name=john1&note=coder", "application/x-www-form-urlencoded");
```
### POST with parameters
```c++
httplib::Map params;
params["name"] = "john";
params["note"] = "coder";
auto res = cli.post("/post", params);
```
### With Progress Callback
```cpp