【问题标题】:cpprestsdk http_client constructor errorscpprestsdk http_client 构造函数错误
【发布时间】:2021-03-06 07:05:40
【问题描述】:

我在两个不同的独立项目中使用下面的代码。

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());
        }

项目 1:是一个更大的项目 项目2:一个只包含下面的代码

当我编译和运行项目 2 时,没有发生错误,代码工作正常,但如果我编译项目 1,它编译没有错误,但在运行时,uri_builder builder(U("/search")); 出现错误,上面写着:

在 Sgimri_TC2_V2.exe 中的 0x00007FF643034EE7 处引发异常:0xC0000005:在位置 0x0000000000000000 读取访问暴力。 (我把它从德语翻译成英语)

此错误发生在此处的 xstring 中:

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();
    }

具体的错误发生在这一行_Construct_lv_contents(_Right);

这与uri_builder 的构造函数有关,其中某些组件为NULL。 here也发生过类似的事情,但我不知道如何解决。

有没有人有我可以帮助我的解决方案、提示或建议?会很棒!

谢谢。

【问题讨论】:

    标签: c++ rest constructor null cpprest-sdk


    【解决方案1】:

    我自己解决了这个问题。这是我如何解决问题的简短方法。

    我使用 MS Visual Studio 2019 并将我的项目编译为 x64, Release 版本。在将其更改为 x64, Debug 并在 Project Properties -> C/C++ 代码生成 -> Runtime Library 中更改项目设置为 Multithreaded-Debug-DLL(/MDd)它编译并运行没有错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-15
      • 2012-07-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      • 2016-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多