client.request method is skipped

Apr 28, 2014 at 10:22 AM
I want to write a little c++ program that sends a request to a server an get some data. What i got now is that code but the client.request method is skipped. The program never jumps in. Hope someone can realise the problem and maybe explain what i have to change.
#include <Windows.h>
#include <iostream>
#include <sstream>
#include <string>
#include "cpprest/containerstream.h"
#include "cpprest/filestream.h"
#include "cpprest/http_client.h"
#include "cpprest/json.h"
#include "cpprest/producerconsumerstream.h"
#include "cpprest/http_client.h"
#include <string.h>
#include <conio.h>

using namespace std;
using namespace web;
using namespace web::json;
using namespace web::http;
using namespace web::http::client;
using namespace utility;
using namespace utility::conversions;


int main() {

  http_client client(L"http://httpbin.org/ip");

  client.request(methods::GET).then([](http_response response)
  { 
    if(response.status_code() == status_codes::OK)
    {
      auto body = response.extract_string().get();    
      std::wcout << body;
      getch();
    }
  });


  return 0;
}
Apr 28, 2014 at 5:13 PM
Hi ZarakiKen,

The main thread terminated before the "request" task completed, so you cannot see any console outputs. I suggest you to call the task "wait()" function after ".then".
  client.request(methods::GET).then([](http_response response)
  { 
    if(response.status_code() == status_codes::OK)
    {
      auto body = response.extract_string().get();    
      std::wcout << body;
      getch();
    }
  }).wait();


  return 0;
Apr 29, 2014 at 8:46 AM
Thank you! But now i get an exception: Expression _isCompleted()

Is it necessary to call something like a "Completefunction" ?
Apr 30, 2014 at 6:38 PM
Can you post the call stack of this exception? This can help us to investigate.

Thanks