I use the code below in two different, independent projects.
auto fileStream = std::make_shared<ostream>();
// Open stream to output file.
pplx::task<void> requestTask = fstream::open_ostream(U("results.html"))
.then([=](ostream outFile)
{
*fileStream = outFile;
// Create http_client to send the request.
http_client client(U("http://www.bing.com/"));
// Build request URI and start the request.
uri_builder builder(U("/search"));
builder.append_query(U("q"), U("cpprestsdk github"));
return client.request(methods::GET, builder.to_string());
})
// Handle response headers arriving.
.then([=](http_response response)
{
printf("Received response status code:%u\n", response.status_code());
// Write response body into the file.
return response.body().read_to_end(fileStream->streambuf());
})
// Close the file stream.
.then([=](size_t)
{
return fileStream->close();
})
;
// Wait for all the outstanding I/O to complete and handle any exceptions
try
{
requestTask.wait();
}
catch (const std::exception& e)
{
printf("Error exception:%s\n", e.what());
}
Project 1: is a bigger one with other things Project 2: one just contains the code below
when I compile and run Project 2 no errors occur and the code works perfectly fine, but if I compile Project 1 it compiles without errors, but at runtime an error occurs at uri_builder builder(U("/search"));
which says:
Exception thrown at 0x00007FF643034EE7 in Sgimri_TC2_V2.exe: 0xC0000005: Access violence for read at position 0x0000000000000000. (I translated that from German to English)
this error occurs in xstring here:
public:
basic_string(const basic_string& _Right)
: _Mypair(_One_then_variadic_args_t{}, _Alty_traits::select_on_container_copy_construction(_Right._Getal())) {
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alty, _Getal());
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
_Construct_lv_contents(_Right);
_Proxy._Release();
}
specifically the error occurs in this line _Construct_lv_contents(_Right);
It has to do with the constructor of the uri_builder
where some components are NULL.
Something similar happend in here, but I don't know how to solve it.
Does anyone hase a solution, hint or adivce which my help me? Would be great!
Thanks.
I fixed this problem on my own. Here is a short way on how I solved the problem.
I used MS Visual Studio 2019 and compiled my project as x64, Release
Version. After changing it to x64, Debug
and changed project settings in Project Properties -> C/C++ Code Genereation -> Runtime Library to Multithreaded-Debug-DLL(/MDd) it compiles and runs without errors.
User contributions licensed under CC BY-SA 3.0