I try to send a HTTP (REST) request to a server with cpprestsdk
.
void postRestRequest(const std::string& uri, const std::string& requestJson) {
const std::string host = "localhost:8080";
const http_client_config authorization = setupAuthorization();
http_client client(U(host), authorization);
http_request request(methods::POST);
uri_builder builder(U(uri));
request.set_request_uri(builder.to_string());
if (not requestJson.empty()) {
const auto mimeType = utf8string("application/json; charset=utf-8");
request.set_body(requestJson, mimeType); // SEGFAULT here
}
}
The call stack is:
-|libpthread.so.0
-|[1]
-|
-|libcpprest.so.2.9
-|[2] : pplx::task_completion_event<unsigned long>::set(unsigned long) const+0xb4
-|
-|mylib.so
-|[3] : postRestRequest(std::string const&, std::string const&)+0x49a
I'm not sure if I use the library as expected.
I don't know exactly how the tasks in the pplx
library work.
Could it also be a bug in the cpprestsdk library. But creating HTTP requests is an essential part of a REST framework. So I can't imagine that there is a unknown bug in the librrary.
Linux: RHEL7
cpprestsdk: 2.9
gcc: 6.3.1