libcpr在HTTP请求时不能正常工作



我在Visual Studio 2019 IDE中使用libcpr进行http请求。我用vcpkg从微软下载的。下面的示例代码来自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;

}

这行不通!它给出错误"名称空间"没有成员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在这种情况下";

任何帮助将不胜感激!!

感谢

在我看来像是一个版本问题。AuthMode存在于最新的头文件中,但不存在于1.8版本的头文件中,这可能是您所拥有的。

所以,要么降级代码,要么升级安装。

1.8版本的示例代码在这里

最新更新