From 6c446881d6870621d76fe7b0677aa069ec64a2ac Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sun, 5 Mar 2023 17:43:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0curlpp=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 8 ++++- src/curlpptest_main.cpp | 38 ++++++++++++++++++++ src/main.cpp | 5 +-- src/service/voiceprocess/voiceprocess_service.cpp | 9 +++++ src/service/voiceprocess/voiceprocess_service.hpp | 42 +++++++++++++++++++++++ 5 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 src/curlpptest_main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8130841..5195755 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,12 @@ set(DEP_LINK_LIBRARIES m # sys asound - pthread) + pthread + # + curlpp + curl) +set(PUBLIC_INCLUDE_DIRECTORIES ${PUBLIC_INCLUDE_DIRECTORIES} ./libs/curlpp/include) +set(PUBLIC_LINK_DIRECTORIES ${PUBLIC_LINK_DIRECTORIES} ./libs/curlpp/lib) # 添加编译的目标文件 zadd_executable_simple( @@ -89,3 +94,4 @@ zadd_executable_simple(TARGET alsaplayer_main.out SRC dep/zlinuxcomponents/alsaplayer/alsaplayer_main.cpp) zadd_executable_simple(TARGET audio_recorder_main.out SRC dep/zlinuxcomponents/audio/audio_recorder_main.cpp) +zadd_executable_simple(TARGET curlpptest_main.out SRC src/curlpptest_main.cpp) diff --git a/src/curlpptest_main.cpp b/src/curlpptest_main.cpp new file mode 100644 index 0000000..96f831a --- /dev/null +++ b/src/curlpptest_main.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + try { + std::string url = "https://www.example.com"; + curlpp::Cleanup cleaner; + curlpp::Easy request; + + // 设置请求的 URL + request.setOpt(new curlpp::options::Url(url)); + + // 将响应数据存储到一个字符串中 + std::ostringstream response; + request.setOpt(new curlpp::options::WriteStream(&response)); + // 执行请求并检查返回状态码 + request.perform(); + long http_code = curlpp::infos::ResponseCode::get(request); + if (http_code == 200) { + std::cout << "Response: " << response.str() << std::endl; + } else { + std::cerr << "Error: HTTP status code " << http_code << std::endl; + } + } catch (curlpp::RuntimeError &e) { + std::cerr << "Error: " << e.what() << std::endl; + return 1; + } catch (curlpp::LogicError &e) { + std::cerr << "Error: " << e.what() << std::endl; + return 1; + } + + return 0; +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 42951d7..f78cc73 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,9 @@ // #include "zlinuxcomponents/alsaplayer/AudioPlayerAlsaImpl.hpp" // #include "zlinuxcomponents/audio/audio_recoder.hpp" - +#include +#include +#include // using namespace iflytop; using namespace core; @@ -44,7 +46,6 @@ int Main::main(int argc, char *argv[]) { #endif logger->info("system setup start."); - spdlog::flush_on(spdlog::level::debug); logger->info("#"); diff --git a/src/service/voiceprocess/voiceprocess_service.cpp b/src/service/voiceprocess/voiceprocess_service.cpp index e69de29..15b0ce5 100644 --- a/src/service/voiceprocess/voiceprocess_service.cpp +++ b/src/service/voiceprocess/voiceprocess_service.cpp @@ -0,0 +1,9 @@ +#include "voiceprocess_service.hpp" + +#include "iflytopcpp/core/spdlogfactory/logger.hpp" + +using namespace iflytop; +using namespace std; +using namespace core; + +void VoiceProcessService::initialize() {} \ No newline at end of file diff --git a/src/service/voiceprocess/voiceprocess_service.hpp b/src/service/voiceprocess/voiceprocess_service.hpp index e69de29..3d3d2c6 100644 --- a/src/service/voiceprocess/voiceprocess_service.hpp +++ b/src/service/voiceprocess/voiceprocess_service.hpp @@ -0,0 +1,42 @@ +// +// Created by zwsd +// + +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "iflytopcpp/core/spdlogfactory/logger.hpp" +#include "iflytopcpp/core/thread/thread.hpp" + +/** + * @brief + * + * service: VoiceProcessService + * + * 监听事件: + * 依赖状态: + * 依赖服务: + * 作用: + * + */ + +namespace iflytop { +using namespace std; +using namespace core; +class VoiceProcessService : public enable_shared_from_this { + ENABLE_LOGGER(VoiceProcessService); + + public: + VoiceProcessService(){}; + + void initialize(); +}; +} // namespace iflytop \ No newline at end of file