c++调试断言HTTP请求失败

标签 c++ http casablanca

我正在编写一些代码,我需要执行 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();
   //...
}

当我使用调试时,我在以下行中收到错误:

返回 client.request(methods::GET).then([](http_response 响应)

通过调试,我看到变量“client”有内容,但我仍然收到此错误:

Image with the Error Message

我用谷歌搜索错误,大多数人说这是代码错误(试图访问内存的某些部分)...

有什么想法吗?

最佳答案

当 cpprestsdk DLL 使用Multi-Threaded DLL /MD 构建并且调用库使用Multi-Threaded 构建时,可能会发生此问题> /MT。由于 cpprestsdk 不提供 .lib 文件的配置,您不得不使用 /MD。至少据我所知这是最好的,因为我无法在没有一堆链接器错误的情况下开箱即用地编译 cpprestsdk.lib。

关于c++调试断言HTTP请求失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41486307/

相关文章:

c++ - 将文本文件解析为 C++ 有向图或邻接表?

c# - 将图像传递给 openCV 中的 blur() 或 Canny() 时出现类似幽灵的伪像

android - 为 Android 应用程序和 Django 数据库制作 RESTful http 服务?

http - 如何使 curl 发布一个参数,从文件中读取它的值?

visual-c++ - 在卡萨布兰卡发布文本请求(C++ REST SDK)

c++ - 使用 C++ REST SDK Casablanca 发送 HTTP POST 请求以更新文件内容

c++ - R 调用 Cpp 代码 : global variables not re-initialized

c++ - 列表丢失了列表 C 中的最后一项

javascript - 使用JavaScript从客户端浏览器上传到Google Cloud Storage

c++ - 如何修复 cpprestsdk 中的 "error in ssl handshake"?