Browse Source

添加curlpp支持

master
zhaohe 2 years ago
parent
commit
6c446881d6
  1. 8
      CMakeLists.txt
  2. 38
      src/curlpptest_main.cpp
  3. 5
      src/main.cpp
  4. 9
      src/service/voiceprocess/voiceprocess_service.cpp
  5. 42
      src/service/voiceprocess/voiceprocess_service.hpp

8
CMakeLists.txt

@ -66,7 +66,12 @@ set(DEP_LINK_LIBRARIES
m m
# sys # sys
asound 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( zadd_executable_simple(
@ -89,3 +94,4 @@ zadd_executable_simple(TARGET alsaplayer_main.out SRC
dep/zlinuxcomponents/alsaplayer/alsaplayer_main.cpp) dep/zlinuxcomponents/alsaplayer/alsaplayer_main.cpp)
zadd_executable_simple(TARGET audio_recorder_main.out SRC zadd_executable_simple(TARGET audio_recorder_main.out SRC
dep/zlinuxcomponents/audio/audio_recorder_main.cpp) dep/zlinuxcomponents/audio/audio_recorder_main.cpp)
zadd_executable_simple(TARGET curlpptest_main.out SRC src/curlpptest_main.cpp)

38
src/curlpptest_main.cpp

@ -0,0 +1,38 @@
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
#include <curlpp/cURLpp.hpp>
#include <curlpp/Infos.hpp>
#include <iostream>
#include <sstream>
#include <string>
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;
}

5
src/main.cpp

@ -18,7 +18,9 @@
// //
#include "zlinuxcomponents/alsaplayer/AudioPlayerAlsaImpl.hpp" #include "zlinuxcomponents/alsaplayer/AudioPlayerAlsaImpl.hpp"
// #include "zlinuxcomponents/audio/audio_recoder.hpp" // #include "zlinuxcomponents/audio/audio_recoder.hpp"
#include <curl/curl.h>
#include <iostream>
#include <string>
// //
using namespace iflytop; using namespace iflytop;
using namespace core; using namespace core;
@ -44,7 +46,6 @@ int Main::main(int argc, char *argv[]) {
#endif #endif
logger->info("system setup start."); logger->info("system setup start.");
spdlog::flush_on(spdlog::level::debug); spdlog::flush_on(spdlog::level::debug);
logger->info("#"); logger->info("#");

9
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() {}

42
src/service/voiceprocess/voiceprocess_service.hpp

@ -0,0 +1,42 @@
//
// Created by zwsd
//
#pragma once
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#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<VoiceProcessService> {
ENABLE_LOGGER(VoiceProcessService);
public:
VoiceProcessService(){};
void initialize();
};
} // namespace iflytop
Loading…
Cancel
Save