Probably you are missing #include "stdafx.h" line at the top of the program. It's needed for Visual Studio C++. It's not to be used with Linux. I've edited your program to make it a bit simpler. The program only work on Windows.
When submitting an issue, it's best to whittle down the program to the absolute minimum code required to demonstrate the problem. Also mention the compiler, system and error messages. We can't read your mind, you know.
When submitting an issue, it's best to whittle down the program to the absolute minimum code required to demonstrate the problem. Also mention the compiler, system and error messages. We can't read your mind, you know.
// Windows listener demo
#include "stdafx.h"
#include <cpprest/http_client.h>
#include <cpprest/http_listener.h>
using namespace std;
using namespace utility; // Common utilities like string conversions
using namespace web; // Common features like URIs.
using namespace web::http; // Common HTTP functionality
using namespace web::http::client; // HTTP client features
using namespace web::http::experimental::listener;
int main(int argc, char *args[])
{
// Be sure to allow traffic on http://localhost:8080/msg
// Server side process
http_listener listenerVoices_1(U("http://localhost:8080/msg"));
std::wcout << "Program: Listening uri:" << listenerVoices_1.uri().to_string() << endl;
listenerVoices_1.support(web::http::methods::GET, [](web::http::http_request request)
{
string_t msg = U("Server: uri:") + request.request_uri().to_string() + U(" Time:") + string_t(to_wstring(time(nullptr)));
std::wcout << msg << endl;
request.reply(web::http::status_codes::OK, msg);
}
);
listenerVoices_1.open().wait();
// Client side process
http_client client(U("http://localhost:8080/msg"));
client.request(methods::GET).then([](http_response response)
{
if (response.status_code() == status_codes::OK)
{
auto body = response.extract_string().get();
std::wcout << "Client: Return:" << response.status_code() << " Body:" << body << endl;
}
});
std::wcout << "Program: Press any enter to close" << endl;
getchar();
listenerVoices_1.close().wait();
std::wcout << "Program: Press any enter to end" << endl;
getchar();
return 0;
}