我正在做一些代码,我需要做一个GET请求并操纵收到的信息。为此,我使用C ++ REST SDK(代号为“Casablanca”)作为请求
这是我的代码
#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();
//...
}
当我使用debug时,我会在以下行中收到错误:
返回client.request(methods :: GET).then([](http_response response)
使用debug我看到变量“client”有内容,但我仍然收到此错误:
我认为它是错误的,并且大多数人都说这是代码错误(试图访问内存的某些部分)...
有什么想法吗?
答案 0 :(得分:1)
使用Multi-Threaded DLL
/MD
构建cpprestsdk DLL并使用Multi-Threaded
/MT
构建调用库时,可能会发生此问题。由于cpprestsdk不提供.lib文件的配置,因此您被迫使用/MD
。至少这是我所知道的,因为我没有能够在没有一堆链接器错误的情况下编译cpprestsdk.lib。