1

I'm doing some code where i need to do a GET request and manipulate the info received. For this i'm using C++ REST SDK (codename "Casablanca") for the request

This is my code

#include <cpprest/http_client.h>
#include <cpprest/filestream.h>

using namespace utility;                    
using namespace web;                        
using namespace web::http;                 
using namespace web::http::client;          
using namespace concurrency::streams;    


//This method i saw on the Microsoft documentation
pplx::task<void> HTTPStreamingAsync()
{    
    http_client client(L"http://localhost:10000/Something"); //The api is running at the moment

    // Make the request and asynchronously process the response. 

    return client.request(methods::GET).then([](http_response response)
    {
        // Print the status code.
        std::wostringstream ss;
        ss << L"Server returned returned status code " << response.status_code() << L'.' << std::endl;
        std::wcout << ss.str();

        // TODO: Perform actions here reading from the response stream.
        auto bodyStream = response.body();

        // In this example, we print the length of the response to the console.
        ss.str(std::wstring());
        ss << L"Content length is " << response.headers().content_length() << L" bytes." << std::endl;
        std::wcout << ss.str();
    });
}   



void main(int argc, char **argv)
{
   HTTPStreamingAsync().wait();
   //...
}

And when i use debug i get error on the following line:

return client.request(methods::GET).then([](http_response response)

With debug i see that variable "client" has content, but i still receive this error:

Image with the Error Message

I google it the error, and most of the people say that it is error on the code (trying to access some parts of the memory)...

Any ideas?

Tazz
  • 79
  • 13
  • Somewhere else, you may have `__acrt_first_block == header` and this is being used as an assertion, which fails (`false`). The Microsoft code you pasted in your question is performing that assertion and indicates it... So you may need to add more details in order for people to help you. – CPHPython Jan 05 '17 at 15:25
  • I searched in all files from the project and i didn't find any " __acrt_first_block == header ".The code above its all the code i have in this project – Tazz Jan 05 '17 at 15:41
  • Now i fixed the problem. Now i have other problem with the response body that always return 1, but i will fix it!. Thanks all for the help! :) – Tazz Jan 06 '17 at 11:08
  • Well done @Tazz, can you please post an answer to your own question explaining how you solved your problem? This may help other people, and you may get reputation by doing so. – CPHPython Jan 06 '17 at 11:11

1 Answers1

1

This issue can happen when the cpprestsdk DLL is build with Multi-Threaded DLL /MD and the calling library is build with Multi-Threaded /MT. Since the cpprestsdk does not offer a configuration for a .lib file, you are forced to use /MD. At least that is best to my knowledge, as I haven't been able to compile cpprestsdk.lib out of the box without a bunch of linker errors.

pascalx
  • 101
  • 2
  • 3