如何使用POCO库将C ++对象传输到Web服务 [英] How to transfer a C++ object to a web service using POCO library

查看:123
本文介绍了如何使用POCO库将C ++对象传输到Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Qt和openCV的图像处理应用程序。

I have an image processing application that uses Qt and openCV.

对于每个帧,我应该将捕获的cv :: Mat image对象发送到服务器来处理它并获得结果。

for each frame, I should send the captured cv::Mat image object to the server to process it and get the results.

我应该使用REST架构的低播放。

I should use the REST architecture for its low playload.

我应该使用什么工具将cv :: Mat发送到服务器。

What is the tool that I should use to send cv::Mat to the server.

使用POCO的可移植性。

I am using POCO for portability.

我寻求最轻的解决方案,我需要服务器在一秒钟处理的最少10帧的速度。

I seek for the lightest solution to do that, I need a minimum speed of 10 frames processed by the server in a second.

我的意思是,有没有一个方法来传递C ++对象到服务器没有显式序列化?

I mean, is there a method to pass the C++ Object to the server without an explicit serialization?

推荐答案

EDIT

使用POCO库,您可以查看此答案:在Poco库中HttpRequest PUT内容。他在 ifstream 上发送一个文件。

With the POCO library, you can take a look in this answer: HttpRequest PUT content in poco library. He is sending a file on a ifstream.

在这个答案你可以检查如何转换 cv :: Mat 转换为 istream OpenCV cv :: Mat to std :: ifstream for base64 encoding

In this answer you can check how to convert a cv::Mat into a istream: OpenCV cv::Mat to std::ifstream for base64 encoding.

到多态性,istream被转换为ifstream。

And finally, Thanks to polymorphism, the istream is implicity converted to a ifstream.

您可以使用C ++ Rest SDK。 PUT命令的代码示例。

You can use the C++ Rest SDK. A code example of the PUT command.

代码来源

Library Github您可以在其中找到完整的文档

#include <http_client.h>
#include <filestream.h>
#include <iostream>
#include <sstream>

using namespace web::http;
using namespace web::http::client;

// Upload a file to an HTTP server.
pplx::task<void> UploadFileToHttpServerAsync()
{
    using concurrency::streams::file_stream;
    using concurrency::streams::basic_istream;

    // To run this example, you must have a file named myfile.txt in the current folder. 
    // Alternatively, you can use the following code to create a stream from a text string. 
    // std::string s("abcdefg");
    // auto ss = concurrency::streams::stringstream::open_istream(s); 

    // Open stream to file. 
    return file_stream<unsigned char>::open_istream(L"myfile.txt").then([](pplx::task<basic_istream<unsigned char>> previousTask)
    {
        try
        {
            auto fileStream = previousTask.get();

            // Make HTTP request with the file stream as the body.
            http_client client(L"http://www.fourthcoffee.com");
            return client.request(methods::PUT, L"myfile", fileStream).then([fileStream](pplx::task<http_response> previousTask)
            {
                fileStream.close();

                std::wostringstream ss;
                try
                {
                    auto response = previousTask.get();
                    ss << L"Server returned returned status code " << response.status_code() << L"." << std::endl;
                }
                catch (const http_exception& e)
                {
                    ss << e.what() << std::endl;
                }
                std::wcout << ss.str();
            });
        }
        catch (const std::system_error& e)
        {
            std::wostringstream ss;
            ss << e.what() << std::endl;
            std::wcout << ss.str();

            // Return an empty task. 
            return pplx::task_from_result();
        }
    });

    /* Sample output:
    The request must be resent
    */
}

这篇关于如何使用POCO库将C ++对象传输到Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆