How to configure http_listener to listen on my ip address so other computers on the network can send requests to the server ?
http_listener listener(L"http://localhsot:9000"); // not working
http_listener listener(L"http://0.0.0.0:9000"); // run time error
http_listener listener(L"http://*:9000"); // run time error
I want to use c++ rest sdk as a server on my local network .
The reason why http_listener listener(L"http://localhsot:9000");
isn't working is because "localhost" is spelled wrong.
Once you correct the misspelling, you should be able to point your web browser to http://localhost:9000 and you'll receive the request. Test it with a print function.
As mentioned, don't forget to set up the support for the request.
Listener.support(methods::GET, std::bind(&HandleGet, this, std::placeholders::_1));
and the HandleGet function (if GET request)
HandleGet(http_request request)
{
std::wcout << L"Received GET request" << std::endl;
}
So after this has been setup, point your web browser to the address, and you should see the output.
Also, you can wrap the ServerInit.open().wait()
(starts the listening) in a try/catch
to see why it's not working.