首页 > 解决方案 > 使用 C++ REST SDK 创建 HTTP 客户端

问题描述

我是 C++ 新手,最近尝试了C++ REST SDK:但我似乎无法按照此处的教程创建 http_client 对象。我现在完全被卡住了:/

我正在使用 Linux Mint 和最新版本的 Eclipse。当我将鼠标悬停在http_client client(U("http://www.bing.com/"))它说的对象上时Invalid arguments 'Candidates are: http_client(const web::http::client::http_client &)'。我只尝试了字符串,http_client client("http://www.bing.com/")结果相同。我查看了文档,它只是说要提供一个字符串。我搜索了不同的教程和帖子,它要么只使用字符串“http://...”,要么使用宏 U, U("http://www.bing.com/")

我还查看了“什么是实用程序::string_t 和 'U' 宏?”部分。在Github上,但我不确定除了使用 U 来创建正确类型的字符串文字外,我还不确定它的用途,具体取决于您使用的操作系统。

#include <iostream>
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>

using namespace utility;                    // Common utilities like string conversions
using namespace web;                        // Common features like URIs.
using namespace web::http;                  // Common HTTP functionality
using namespace web::http::client;          // HTTP client features
using namespace concurrency::streams;       // Asynchronous streams

int main()
{
    auto fileStream = std::make_shared<ostream>();

    // Open stream to output file.
    pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
    {
        *fileStream = outFile;
        
        http_client client(U("http://www.bing.com/"));
    });
        
    return 0;
}

标签: c++apiresthttpclient

解决方案


推荐阅读