0

I've built Casablanca and all other dependencies correctly in Ubuntu 16.04. But when I follow those C++ examples on this site, I found the program cannot find methods::GET member. It only shows methods, but no child member of it. What did I miss? Thank you in advance.

Update:

Here's the code I use:

#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();
});
}
E_learner
  • 3,512
  • 14
  • 57
  • 88

1 Answers1

0

It is not clear why your program does not find GET, no exact error was specified.
Also the documentation you are using is bit old, please try following samples from cpprestsdk's sources from github.

Anyway, as you specified Ubuntu 16.04, I assume you are using GCC. I am able to succesfully run your source code using only few modifications, full sample code:

#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 compiled from sources. Program compiled using gcc 7.2.1:

g++ -I/usr/local/include/cpprest -o ct main.cpp -lcpprest -lboost_system -lcrypto
pe3k
  • 796
  • 5
  • 15
  • Thank you for your answer. I also built from souce using gcc. However it still doesn't show me `GET` or any other child member for `methods`. I tried to read through the original `header` or `cpp` files of `web::http`, but still they don't seem to include these child members. Do you have any idea? – E_learner Dec 27 '17 at 07:57
  • @Gibet Unfortunately, no. The example code above also gives the same error. – E_learner Dec 27 '17 at 13:02