2010-11-19 394 views
7

是否有任何开源库可用于C++中实现RESTful客户端(用于解释HTTP请求作为REST服务调用的库)?C++中的RESTful客户端API

我的要求是连接到亚马逊网络服务,并获取可用于C++中给定用户帐户的EC2实例(及其详细信息)的列表。

我知道亚马逊在Java,C#中为此提供了API。但我想用C++。如果亚马逊也提供C++,那就没问题了,请指导我。

非常感谢您的帮助。

Regards

Bharatha Selvan。

回答

2

您需要解析XML。我建议你试试Qt C++ Toolkit,它会给你一个QHttp实例来进行HTTP调用和QtXml模块来解析xml。这样你可以创建一个C++ Rest客户端。

2

您应该尝试ffead-cpp网络框架。它具有许多其他功能,如依赖注入,序列化,有限反射,JSON等等。请检查...

0

Restbed提供同步和异步HTTP/HTTPS客户端功能。

#include <memory> 
#include <future> 
#include <cstdio> 
#include <cstdlib> 
#include <restbed> 

using namespace std; 
using namespace restbed; 

void print(const shared_ptr<Response>& response) 
{ 
    fprintf(stderr, "*** Response ***\n"); 
    fprintf(stderr, "Status Code: %i\n", response->get_status_code()); 
    fprintf(stderr, "Status Message: %s\n", response->get_status_message().data()); 
    fprintf(stderr, "HTTP Version: %.1f\n", response->get_version()); 
    fprintf(stderr, "HTTP Protocol: %s\n", response->get_protocol().data()); 

    for (const auto header : response->get_headers()) 
    { 
     fprintf(stderr, "Header '%s' > '%s'\n", header.first.data(), header.second.data()); 
    } 

    auto length = 0; 
    response->get_header("Content-Length", length); 

    Http::fetch(length, response); 

    fprintf(stderr, "Body:   %.*s...\n\n", 25, response->get_body().data()); 
} 

int main(const int, const char**) 
{ 
    auto request = make_shared<Request>(Uri("http://www.corvusoft.co.uk:80/?query=search%20term")); 
    request->set_header("Accept", "*/*"); 
    request->set_header("Host", "www.corvusoft.co.uk"); 

    auto response = Http::sync(request); 
    print(response); 

    auto future = Http::async(request, [ ](const shared_ptr<Request>, const shared_ptr<Response> response) 
    { 
     fprintf(stderr, "Printing async response\n"); 
     print(response); 
    }); 

    future.wait(); 

    return EXIT_SUCCESS; 
}