Issue sending http request, no connection at all?

Aug 1, 2014 at 10:31 PM
Edited Aug 1, 2014 at 10:40 PM
I am currently writing a small piece of code to familiarize myself with the REST SDK's JSON capabilities some more and following the JSON example in the documentation I have this:
pplx::task<void> WoWRealmCheck() {
    uri_builder uribuild(L"");
    auto uri = uribuild.to_uri();
    http_client client(uri);
    return client.request(methods::GET)
        .then([](http_response response) -> pplx::task<json::value>
        std::cout << "Received response code: " << response.status_code() << std::endl;
        if (response.status_code() == status_codes::OK)
            return response.extract_json();
            return pplx::task_from_result(json::value());

        .then([](pplx::task<json::value> jsonResponse)
            const json::value& v = jsonResponse.get();
            std::cout << "Check 2\n";
        catch (const web::http::http_exception& e)
            std::cout << e.what();

int main() {
    std::cout << "Checking current status of all realms...\n";

The issue is the code does not even show a connection to the http client, it gets as the first return statement in the realm check function and then nothing, no message for response code or anything, it just cuts straight to the end of the run. I would love for someone to let me know what I'm doing incorrectly thank you.

Edit: I also know for sure the host I am connecting to provides data in the form of json per get request, is the api I am using.
Aug 3, 2014 at 8:57 AM
Suggest you try the URL in a browser. What does it return?

The shorter the program, the more likely you are to get feedback. Try reposting as a program of around 10 lines.
Aug 3, 2014 at 7:31 PM
Hi GrandaThePanda,

I didn't try your code out but looking at it, it looks like you are starting and asynchronous operation and not waiting for it complete. Your function WowRealmCheck returns a task, from calling http_client::request. In the main method of your program you are calling WowRealmCheck and not waiting the returned task, instead immediately exiting the process. If you add a call to wait on the task you should be all set. So you main would look something like this:
int main() {
    std::cout << "Checking current status of all realms...\n";
Please note all potentially blocking operations in the C++ Rest API are asynchronous and return a Parallel Patterns Library task. Here are a couple of resources you can look at for how to use and write programs with tasks.

Aug 4, 2014 at 12:11 AM

Thank you very much that did the trick and thank you very much for the resources, I'm new to working with ppl, so that helps greatly.