最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

Poco库完全使用手册

IT圈 admin 41浏览 0评论

2024年2月14日发(作者:郜安吉)

bool UpdateTask::fetchUpdateInfoFromHTTPServer(){ //请求的参数 std::string arg1 = "1"; std::string arg2 = "2"; std::string arg3 = "3"; //拼接对应的请求 Config config; std::string path = "/api/v1/update"; Poco::URI uri; eme(verScheme()); t(verAddr()); t(verPort()); h(path); ryParameter("arg1", arg1); ryParameter("arg2", arg2); ryParameter("arg3", arg3); Poco::Net::HTTPSClientSession* https_session = OSUtils::CommonUtils::GetHttpsClientSession(); https_session->setPort(t()); https_session->setHost(t()); std::string pathAndQuery(hAndQuery());

Poco::Net::HTTPRequest request( Poco::Net::HTTPRequest::HTTP_GET, pathAndQuery, Poco::Net::HTTPMessage::HTTP_1_1); Poco::Net::HTTPResponse response; https_session->sendRequest(request); std::istream &streamIn = https_session->receiveResponse(response); std::ostringstream responseStream; Poco::StreamCopier::copyStream(streamIn, responseStream); m_responseContent = (); delete https_session; https_session = nullptr; return tus() == Poco::Net::HTTPResponse::HTTP_OK;}HTTP POST下载请求int MyUpdateTask::UpdateWork(std::string loginid, std::string clientid, std::string& filePath){ try { Config config; std::string path = "/api/v1/dict/download"; Poco::URI uri; eme(verScheme()); t(verAddr()); t(verPort()); h(path); Poco::Net::HTTPSClientSession* https_session = OSUtils::CommonUtils::GetHttpsClientSession(); https_session->setHost(t()); https_session->setPort(t()); Poco::Net::HTTPRequest request( Poco::Net::HTTPRequest::HTTP_POST, hAndQuery(), Poco::Net::HTTPMessage::HTTP_1_1);

Poco::Net::HTMLForm form; ("loginid", loginid); ("clientid", clientid); eSubmit(request); (https_session->sendRequest(request)); Poco::Net::HTTPResponse response; std::istream &streamIn = https_session->receiveResponse(response);

if (tus() != Poco::Net::HTTPResponse::HTTP_OK) { delete https_session; https_session = nullptr; return 1; } std::ostringstream responseStream; Poco::StreamCopier::copyStream(streamIn, responseStream); std::string resultStr = (); delete https_session; https_session = nullptr; Poco::JSON::Parser parser; auto root = (resultStr); Poco::JSON::Object::Ptr objRoot = t(); if (!objRoot) return 2; int codeResult = objRoot->getValue("code"); if (codeResult == 200) {

dictFilePath = objRoot->getValue("result"); return 0; } return codeResult; } catch (...) { return 1; }}https Post MultiPart请求int MyUpdateTask::UpdateWork(std::string loginid, std::string clientid, std::string path){ try { //获得对应的请求参数 Config config; std::string path = "/api/v1/dict/ceshi"; Poco::URI uri; eme(verScheme()); t(verAddr()); t(verPort()); h(path); //获得对应的会话客户端 Poco::Net::HTTPSClientSession* https_session = OSUtils::CommonUtils::GetHttpsClientSession(); https_session->setHost(t());

2024年2月14日发(作者:郜安吉)

bool UpdateTask::fetchUpdateInfoFromHTTPServer(){ //请求的参数 std::string arg1 = "1"; std::string arg2 = "2"; std::string arg3 = "3"; //拼接对应的请求 Config config; std::string path = "/api/v1/update"; Poco::URI uri; eme(verScheme()); t(verAddr()); t(verPort()); h(path); ryParameter("arg1", arg1); ryParameter("arg2", arg2); ryParameter("arg3", arg3); Poco::Net::HTTPSClientSession* https_session = OSUtils::CommonUtils::GetHttpsClientSession(); https_session->setPort(t()); https_session->setHost(t()); std::string pathAndQuery(hAndQuery());

Poco::Net::HTTPRequest request( Poco::Net::HTTPRequest::HTTP_GET, pathAndQuery, Poco::Net::HTTPMessage::HTTP_1_1); Poco::Net::HTTPResponse response; https_session->sendRequest(request); std::istream &streamIn = https_session->receiveResponse(response); std::ostringstream responseStream; Poco::StreamCopier::copyStream(streamIn, responseStream); m_responseContent = (); delete https_session; https_session = nullptr; return tus() == Poco::Net::HTTPResponse::HTTP_OK;}HTTP POST下载请求int MyUpdateTask::UpdateWork(std::string loginid, std::string clientid, std::string& filePath){ try { Config config; std::string path = "/api/v1/dict/download"; Poco::URI uri; eme(verScheme()); t(verAddr()); t(verPort()); h(path); Poco::Net::HTTPSClientSession* https_session = OSUtils::CommonUtils::GetHttpsClientSession(); https_session->setHost(t()); https_session->setPort(t()); Poco::Net::HTTPRequest request( Poco::Net::HTTPRequest::HTTP_POST, hAndQuery(), Poco::Net::HTTPMessage::HTTP_1_1);

Poco::Net::HTMLForm form; ("loginid", loginid); ("clientid", clientid); eSubmit(request); (https_session->sendRequest(request)); Poco::Net::HTTPResponse response; std::istream &streamIn = https_session->receiveResponse(response);

if (tus() != Poco::Net::HTTPResponse::HTTP_OK) { delete https_session; https_session = nullptr; return 1; } std::ostringstream responseStream; Poco::StreamCopier::copyStream(streamIn, responseStream); std::string resultStr = (); delete https_session; https_session = nullptr; Poco::JSON::Parser parser; auto root = (resultStr); Poco::JSON::Object::Ptr objRoot = t(); if (!objRoot) return 2; int codeResult = objRoot->getValue("code"); if (codeResult == 200) {

dictFilePath = objRoot->getValue("result"); return 0; } return codeResult; } catch (...) { return 1; }}https Post MultiPart请求int MyUpdateTask::UpdateWork(std::string loginid, std::string clientid, std::string path){ try { //获得对应的请求参数 Config config; std::string path = "/api/v1/dict/ceshi"; Poco::URI uri; eme(verScheme()); t(verAddr()); t(verPort()); h(path); //获得对应的会话客户端 Poco::Net::HTTPSClientSession* https_session = OSUtils::CommonUtils::GetHttpsClientSession(); https_session->setHost(t());

发布评论

评论列表 (0)

  1. 暂无评论