|
@@ -261,52 +261,6 @@ int main() {
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-**js axios style**
|
|
|
|
|
-```c++
|
|
|
|
|
-#include "axios.h"
|
|
|
|
|
-
|
|
|
|
|
-int main() {
|
|
|
|
|
- const char* strReq = R"({
|
|
|
|
|
- "method": "POST",
|
|
|
|
|
- "url": "http://127.0.0.1:8080/echo",
|
|
|
|
|
- "params": {
|
|
|
|
|
- "page_no": "1",
|
|
|
|
|
- "page_size": "10"
|
|
|
|
|
- },
|
|
|
|
|
- "headers": {
|
|
|
|
|
- "Content-Type": "application/json"
|
|
|
|
|
- },
|
|
|
|
|
- "body": {
|
|
|
|
|
- "app_id": "123456",
|
|
|
|
|
- "app_secret": "abcdefg"
|
|
|
|
|
- }
|
|
|
|
|
- })";
|
|
|
|
|
-
|
|
|
|
|
- // sync
|
|
|
|
|
- auto resp = axios::axios(strReq);
|
|
|
|
|
- if (resp == NULL) {
|
|
|
|
|
- printf("request failed!\n");
|
|
|
|
|
- } else {
|
|
|
|
|
- printf("%s\n", resp->body.c_str());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // async
|
|
|
|
|
- int finished = 0;
|
|
|
|
|
- axios::axios(strReq, [&finished](const HttpResponsePtr& resp) {
|
|
|
|
|
- if (resp == NULL) {
|
|
|
|
|
- printf("request failed!\n");
|
|
|
|
|
- } else {
|
|
|
|
|
- printf("%s\n", resp->body.c_str());
|
|
|
|
|
- }
|
|
|
|
|
- finished = 1;
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // wait async finished
|
|
|
|
|
- while (!finished) hv_sleep(1);
|
|
|
|
|
- return 0;
|
|
|
|
|
-}
|
|
|
|
|
-```
|
|
|
|
|
-
|
|
|
|
|
### WebSocket
|
|
### WebSocket
|
|
|
#### WebSocket server
|
|
#### WebSocket server
|
|
|
see [examples/websocket_server_test.cpp](examples/websocket_server_test.cpp)
|
|
see [examples/websocket_server_test.cpp](examples/websocket_server_test.cpp)
|