基于C++ Coroutines提案 ‘Stackless Resumable Functions’编写的协程库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_async_cinatra_client.cpp 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //依赖 https://github.com/tearshark/modern_cb 项目
  2. //依赖 https://github.com/tearshark/librf 项目
  3. //依赖 https://github.com/qicosmos/cinatra 项目
  4. #include <iostream>
  5. #include "../../cinatra/include/cinatra.hpp"
  6. #include "librf/librf.h"
  7. #include "use_librf.h"
  8. using namespace librf;
  9. using namespace cinatra;
  10. void test_async_cinatra_client()
  11. {
  12. std::string uri = "http://www.baidu.com";
  13. std::string uri1 = "http://cn.bing.com";
  14. std::string uri2 = "https://www.baidu.com";
  15. std::string uri3 = "https://cn.bing.com";
  16. GO
  17. {
  18. auto client = cinatra::client_factory::instance().new_client();
  19. response_data data = co_await client->async_get(uri, use_librf);
  20. print(data.resp_body);
  21. };
  22. GO
  23. {
  24. auto client = cinatra::client_factory::instance().new_client();
  25. response_data data = co_await client->async_get(uri1, use_librf);
  26. print(data.resp_body);
  27. };
  28. GO
  29. {
  30. auto client = cinatra::client_factory::instance().new_client();
  31. response_data data = co_await client->async_post(uri, "hello", use_librf);
  32. print(data.resp_body);
  33. };
  34. #ifdef CINATRA_ENABLE_SSL
  35. GO
  36. {
  37. auto client = cinatra::client_factory::instance().new_client();
  38. response_data data = co_await client->async_get(uri2, use_librf);
  39. print(data.resp_body);
  40. };
  41. GO
  42. {
  43. auto client = cinatra::client_factory::instance().new_client();
  44. response_data data = co_await client->async_get(uri3, use_librf);
  45. print(data.resp_body);
  46. };
  47. #endif
  48. librf::this_scheduler()->run_until_notask();
  49. }