[英]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.所以,要么降级你的代码,要么升级你的安装。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.