Restbed 框架为 C++11 构建的程序带来了 restful 功能,它基于 boost.asio 创建。
Restbed 可用于需要通过 HTTP 无缝和安全通信构建应用程序的全面和一致的编程模型,能够对一系列业务流程进行建模,旨在针对移动,平板电脑,桌面和嵌入式生产环境。
它类似于将 NGINX 嵌入到您公司自己的产品线中。
restbed 实现http 客户端
#include <memory>
#include <future>
#include <cstdio>
#include <cstdlib>
#include <restbed>
#include <string>
#include <iostream>
using namespace std;
using namespace restbed;
int main( const int, const char** )
{
string messsgae_body="{\"hello\":\"yao\"}";
auto request = make_shared< Request >( Uri( "http://localhost:8000/hello" ) );
request->add_header("Content-Type","application/json");
request->add_header("Content-Length",to_string(messsgae_body.length()));
request->set_body(messsgae_body);
auto response = Http::sync( request );
auto length = response->get_header( "Content-Length", 0 );
Http::fetch( length, response );
string response_body((char*) response->get_body().data());
cout<<"response:"<<response_body<<endl;
return EXIT_SUCCESS;
}