I have code something like this
using namespace web;
using namespace http;
const http_response& response = /*valid assignment*/
http_headers::const_iterator it = response.headers().find(L"SomeKey");
if (it != response.headers().end())
{
//doing something
}
response
is having valid data.
It is compiling with windows. I want to compile the same snippet in Linux with g++. How should I handle this?
Do I need to add some flags for compiling?
I got error like this:
error: no matching function for call to ‘web::http::http_headers::find(const wchar_t [17]) const’
http_headers::const_iterator it = response.headers().find(L"SomeKey");
^
The project use wstring
for windows, string
for Linux. And they provide a type string_t
and a macro U
to help deal with this, your code needs to be changed to be compiled both on Windows and Linux.
What is utility::string_t and the 'U' macro? The C++ REST SDK uses a different string type dependent on the platform being targeted. For example for the Windows platforms utility::string_t is std::wstring using UTF-16, on Linux std::string using UTF-8. The 'U' macro can be used to create a string literal of the platform type. If you are using a library causing conflicts with the 'U' macro, for example Boost.Iostreams it can be turned off by defining the macro '_TURN_OFF_PLATFORM_STRING' before including the C++ REST SDK header files.
See this FAQ
A tipical usage:
static const utility::string_t wl_birthday = U("wl.birthday");
static const utility::string_t wl_basic = U("wl.basic");
And for your code:
http_headers::const_iterator it = response.headers().find(U("SomeKey"));
WARN about the status of this project:
cpprestsdk is in maintenance mode and we do not recommend its use in new projects. We will continue to fix critical bugs and address security issues.