方法::在C ++ REST中找不到GET

时间:2017-12-26 13:11:54

标签: c++ rest casablanca

我在Ubuntu 16.04中正确构建了Casablanca和所有其他依赖项。但是当我在documentation for Secondary Constructors网站上关注那些C ++示例时,我发现该程序找不到methods::GET成员。它只显示methods,但没有显示它的子成员。我错过了什么? 先感谢您。

更新

这是我使用的代码:

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

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

// Creates an HTTP request and prints the length of the response stream.
pplx::task<void> HTTPStreamingAsync()
{
    http_client client(L"http://myAddressComesHere");

// Make the request and asynchronously process the response. 
return client.request(methods::GET).then([](http_response response)
{
    // Print the status code.
    std::wostringstream ss;
    ss << L"Server returned returned status code " << response.status_code() << L'.' << std::endl;
    std::wcout << ss.str();

    // TODO: Perform actions here reading from the response stream.
    auto bodyStream = response.body();

    // In this example, we print the length of the response to the console.
    ss.str(std::wstring());
    ss << L"Content length is " << response.headers().content_length() << L" bytes." << std::endl;
    std::wcout << ss.str();
});
}

1 个答案:

答案 0 :(得分:0)

目前尚不清楚为什么你的程序没有找到GET,没有指定确切的错误 您使用的文档也有点旧,请尝试从github上的cpprestsdk&#39; s sources中获取样本。

无论如何,正如您指定的Ubuntu 16.04,我假设您正在使用GCC。我只需要很少的修改就可以成功运行你的源代码,完整的示例代码:

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

using namespace utility;
using namespace web::http;
using namespace web::http::client;
using namespace concurrency::streams;

pplx::task<void> HTTPStreamingAsync() 
{
    http_client client("http://www.google.com"); 

return client.request(methods::GET).then([](http_response response)
{
    std::ostringstream ss;
    ss << "Server returned returned status code " <<    response.status_code() << '.' << std::endl;
    std::cout << ss.str();

    auto bodyStream = response.body();

    ss.str(std::string());
    ss << "Content length is " << response.headers().content_length() << " bytes." << std::endl;
    std::cout << ss.str();
});
}

int main() {
  HTTPStreamingAsync().wait();
}

Cpprestsdk从源头编译。使用gcc 7.2.1编译的程序:

g++ -I/usr/local/include/cpprest -o ct main.cpp -lcpprest -lboost_system -lcrypto