Thanks Steve,
Using std::wstring instead of std::string solved my problem.
Using std::wstring instead of std::string solved my problem.
#include "cpprest/http_client.h"
#include "cpprest/http_listener.h"
#include "concurrent_queue.h"
Concurrency::concurrent_queue<web::http::http_request> cq;
int main()
{
try
{
web::http::experimental::listener::http_listener listener(U("http://192.168.1.104:3901"));
listener.support([=](web::http::http_request request) { cq.push(request); /*request.reply(web::http::status_codes::OK, U("Hello, World!"));*/ });
listener.open().wait();
std::string line;
std::cout << "listening. hit enter to initiate shutdown." << std::endl;
std::getchar();
std::cout << "popping requests" << std::endl;
web::http::http_request request;
while (cq.try_pop(request))
request.reply(web::http::status_codes::ServiceUnavailable);
std::cout << "closing" << std::endl;
Concurrency::task<void> task = listener.close();
std::cout << "waiting" << std::endl;
task.wait();
std::cout << "ending" << std::endl;
}
catch (...)
{
std::cout << "caught error" << std::endl;
}
return(0);
}
-arch x86_64
to line 140 of boost.sh:: $XCODE_ROOT/Toolchains/XcodeDefault.xctoolchain/usr/bin/$COMPILER -arch i386 -fvisibility-inlines-hidden $EXTRA_CPPFLAGS
becomes: $XCODE_ROOT/Toolchains/XcodeDefault.xctoolchain/usr/bin/$COMPILER -arch i386 -arch x86_64 -fvisibility-inlines-hidden $EXTRA_CPPFLAGS
I've copied this into a work item for tracking: https://casablanca.codeplex.com/workitem/196application/x-json
is a MIME type (see http://en.wikipedia.org/wiki/MIME for more details on that). Casablanca expects that JSON payloads will have a MIME type of either application/json (the official MIME type for JSON), text/json, text/x-json, text/javascript, text/x-javascript, application/javascript, or application/x-javascript.application/json
. If you do not control the website, you can work around this by using extract_string
instead of extract_json
and then passing it tojson::value obj = json::value::parse(extracted_string);
Sincerely,How to Learn the C++ REST SDK for any books or websites available?? Please tell me..Thanks,
Please give me a 10 sample Problems for c++ Rest SDK.. because, i practice it..
http_client client(LOGIN_SERVICE_URL);
uri_builder builder(OAUTH2_CONTEXT_PATH);
builder.append_query(L"grant_type", L"password");
builder.append_query(L"username", username);
builder.append_query(L"password", password);
builder.append_query(L"scope", L"send_hybrid");
http_request request(methods::POST);
request.headers().add(L"Authorization", AUTH_STRING);
request.headers().add(L"content-type", L"application/x-www-form-urlencoded");
request.set_request_uri(builder.to_uri());
client.request(request);
and get this unobserved exception:cpprest120d_xp_2_1.dll!Concurrency::details::_ExceptionHolder::~_ExceptionHolder(void) Unknown
cpprest120d_xp_2_1.dll!Concurrency::details::_ExceptionHolder::`scalar deleting destructor'(unsigned int) Unknown
cpprest120d_xp_2_1.dll!std::_Ref_count_obj<struct Concurrency::details::_ExceptionHolder>::_Destroy(void) Unknown
cpprest120d_xp_2_1.dll!std::_Ref_count_base::_Decref(void) Unknown
cpprest120d_xp_2_1.dll!std::_Ptr_base<struct Concurrency::details::_ExceptionHolder>::_Decref(void) Unknown
cpprest120d_xp_2_1.dll!std::shared_ptr<struct Concurrency::details::_ExceptionHolder>::~shared_ptr<struct Concurrency::details::_ExceptionHolder>(void) Unknown
cpprest120d_xp_2_1.dll!Concurrency::details::_Task_completion_event_impl<class web::http::http_response>::~_Task_completion_event_impl<class web::http::http_response>(void) Unknown
cpprest120d_xp_2_1.dll!Concurrency::details::_Task_completion_event_impl<class web::http::http_response>::`scalar deleting destructor'(unsigned int) Unknown
cpprest120d_xp_2_1.dll!std::_Ref_count_obj<struct Concurrency::details::_Task_completion_event_impl<class web::http::http_response> >::_Destroy(void) Unknown
cpprest120d_xp_2_1.dll!std::_Ref_count_base::_Decref(void) Unknown
cpprest120d_xp_2_1.dll!std::_Ptr_base<struct Concurrency::details::_Task_completion_event_impl<class web::http::http_response> >::_Decref(void) Unknown
cpprest120d_xp_2_1.dll!std::shared_ptr<struct Concurrency::details::_Task_completion_event_impl<class web::http::http_response> >::~shared_ptr<struct Concurrency::details::_Task_completion_event_impl<class web::http::http_response> >(void) Unknown
cpprest120d_xp_2_1.dll!Concurrency::task_completion_event<class web::http::http_response>::~task_completion_event<class web::http::http_response>(void) Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::request_context::~request_context(void) Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::winhttp_request_context::~winhttp_request_context(void) Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::winhttp_request_context::`vector deleting destructor'(unsigned int) Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::winhttp_request_context::finish(void) Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::request_context::report_exception(class std::exception_ptr) Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::request_context::report_exception<class web::http::http_exception>(class web::http::http_exception) Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::request_context::report_error(unsigned long,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &) Unknown
cpprest120d_xp_2_1.dll!web::http::client::details::winhttp_client::completion_callback(void *,unsigned long,unsigned long,void *,unsigned long) Unknown
winhttp.dll!73f34b87() Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for winhttp.dll]
[External Code]
The lib was installed as NuGet Package.CreateStreamOnHGlobal
as seen in the code above. I did not find anything appropriate in the samples and I could not make the code work (too black box). I have finally implemented a slopy data extractor that works fine for the purpose. web::http::experimental::listener::http_listener listener(U("http://localhost:3901"));
std::queue<::web::http::http_request> requests;
listener.support([&](::web::http::http_request request) mutable
{
requests.push(request);
});
listener.open().wait();
std::cout << "listening. hit enter to initiate shutdown." << std::endl;
std::getchar();
std::cout << "popping requests" << std::endl;
while (!requests.empty())
{
requests.front().reply(web::http::status_codes::ServiceUnavailable).wait();
requests.pop();
}
std::cout << "closing" << std::endl;
Concurrency::task<void> task = listener.close();
std::cout << "waiting" << std::endl;
task.wait();
std::cout << "ending" << std::endl;
Thanks,