简体   繁体   English

将 libcpr 用于 HTTP 请求时无法正常工作

[英]libcpr not working properly when using it for HTTP request

I am using libcpr for http requests in Visual Studio 2019 IDE.我在 Visual Studio 2019 IDE 中使用 libcpr 处理 http 请求。 I downloaded it using vcpkg from microsoft.我使用微软的 vcpkg 下载了它。 The sample code below is from cpr github page https://github.com/libcpr/cpr#:~:text=%23include%20%3C,return%200%3B%0A%7D下面的示例代码来自 cpr github 页面https://github.com/libcpr/cpr#:~:text=%23include%20%3C,return%200%3B%0A%7D

#include <cpr/cpr.h>

int main(int argc, char** argv) {
    cpr::Response r = 
             cpr::Get(cpr::Url{"https://api.github.com/repos/whoshuu/cpr/contributors"},
                  cpr::Authentication{"user", "pass", cpr::AuthMode::BASIC},
                  cpr::Parameters{{"anon", "true"}, {"key", "value"}});
    r.status_code;                  // 200
    r.header["content-type"];       // application/json; charset=utf-8
    r.text;                         // JSON text string
    return 0;

} }

This doesn't work!这不行! It is giving error "namespace "cpr" has no member "AuthMode". This problem is not with this only. There was some other stuff that gives similar error eg https://docs.libcpr.org/advanced-usage.html#https-options:~:text=cpr%3A%3ASslOptions%20sslOpts%20%3D%20cpr%3A%3ASsl(ssl%3A%3ACaBuffer%7B%22%2D%2D%2D%2D%2DBEGIN%20CERTIFICATE%2D%2D%2D%2D%2D%5B...%5D%22%7D)%3B%0Acpr%3A%3AResponse%20r%20%3D%20cpr%3A%3AGet(cpr%3A%3AUrl%7B%22https%3A//www.httpbin.org/get%22%7D%2C%20sslOpts)%3B in this case "CaBuffer" has same issue.它给出错误“命名空间“cpr”没有成员“AuthMode”。这个问题不仅仅是这个。还有一些其他的东西会给出类似的错误,例如https://docs.libcpr.org/advanced-usage.html# https-options:~:text=cpr%3A%3ASslOptions%20sslOpts%20%3D%20cpr%3A%3ASsl(ssl%3A%3ACaBuffer%7B%22%2D%2D%2D%2D%2DBEGIN%20CERTIFICATE%2D% 2D%2D%2D%2D%5B...%5D%22%7D)%3B%0Acpr%3A%3AResponse%20r%20%3D%20cpr%3A%3AGet(cpr%3A%3AUrl%7B%22https% 3A//www.httpbin.org/get%22%7D%2C%20sslOpts)%3B在这种情况下“CaBuffer”有同样的问题。

Any help would be appreciated!!任何帮助,将不胜感激!!

Thanks谢谢

Looks to me like a versioning issue.在我看来像一个版本问题。 AuthMode exists in the latest header file , but does not exist in the version 1.8 header file , which is presumably what you have. AuthMode存在于最新的头文件中,但不存在于1.8 版本的头文件中,想必是你有的。

So, either downgrade your code, or upgrade your installation.所以,要么降级你的代码,要么升级你的安装。

Sample code from version 1.8 is here 1.8 版的示例代码在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 C++ curl 库 libCPR 获取 HTTP 响应状态代码 0 和空消息 - Getting an HTTP response status code of 0 and empty message using C++ curl library libCPR 如何使用QNetworkAccessManager和QNetworkReply正确执行http GET请求? URL如何影响Qt中的请求? - How to properly do a http GET request using QNetworkAccessManager and QNetworkReply? How does the URL affect the request in Qt? 使用时 <exception> 类中,what()函数似乎无法正常工作 - When using the <exception> class, the what() function seems to not be working properly 使用 QNetworkAccessManager 发送 HTTP 请求 - Sending an HTTP request using QNetworkAccessManager 使用Winsock库发送GET HTTP请求时出现400错误的请求错误 - 400 bad request error when send a GET http request by using winsock library 使用宽字符串时解析罗马数字时,Boost Spirit库无法正常工作 - Boost spirit library not working properly while parsing roman numerals when using wide strings 拨打多个HTTP请求时崩溃 - Crash when making several http request calls 线程使用Qt发送http请求 - Thread sending http request using Qt HTTP 使用 boost::asio 的 POST 请求 - HTTP POST request using boost::asio 使用Xerces-C ++执行HTTP请求 - Using Xerces-C++ to perform an HTTP Request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM