Why not compiled this code?

Nov 12, 2014 at 7:57 AM
Edited Nov 12, 2014 at 8:10 AM
#include "stdafx.h"
#include <iostream>
#include "astreambuf.h"
using namespace http;
using namespace http::listener;
int _tmain(int argc, _TCHAR* argv[])
    uri_builder uri(L"http://localhost:123/");
    http_listener listener;
    listener = http_listener::create(uri.to_uri(),[](http_request msg){
        msg.reply(http::status_codes::OK, U("I'm hosted in native C++!"));
    listener.listen([]() { fgetc(stdin); }).wait();
    return 0;
Nov 12, 2014 at 8:40 PM
Hi Synenkij,

In the future please include the actual compilation errors you are seeing, that information is valuable.

I see several problems with your code. First you aren't including the correct header file, unless it is in your stdafx.h I don't see the cpprest\http_listener.h header file anywhere. Second you are not using the correct namespaces. The http_listener is under the namespace web::http::experimental::listener. Also the functions http_listener::create(...) and http_listener::listen(...) do not exist. Are you trying a old version when this library first started out.

I highly recommend you take a look at some of the documentation and the reference docs, at least for the http_listener which it seems you are interested in.