使用HTTP请求时,LIBCPR无法正常工作

发布于 2025-02-10 00:08:34 字数 1806 浏览 2 评论 0 原文

我正在使用LIBCPR进行HTTP请求,以示为Visual Studio 2019 IDE。我使用Microsoft使用VCPKG下载了它。下面的示例代码来自CPR GITHUB页面 https://github.com/libcpr/cpr#:~: text=%23include%20%20%20%3c,ereturn%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;

}}

这不起作用!它给出错误“命名空间” CPR没有成员“ authmode”。此问题不仅如此。还有其他一些东西给出类似的错误,例如-usage.html#https-options:%7E:文本= CPR%3A%3Assloptions%20SSLOPTS%20%3D%20CPR%3A%3A%3ASSL(SSL%3A%3A%3A%3AACABUFFER%7B%7B%2D%2D%2D%2D%2D%2D%2D%2D%2D%2D%2D%2D%2D%2D%2D%2D%2D% 2DBegin%20certificate%2D%2D%2D%2D%2D%5B ...%5D%22%7D)%3B%0ACPR%3A%3A%3ARESPONSE%20R%20R%20%20%3D%20CPR%20cpr%3A%3A%3AGET(CPR%3A%3A%) 3Aurl%7B%22HTTPS%3A // www.httpbin.org/get%22%7D%2C%20SSlopts)%3B“ rel =“ nofollow noreferrer”> https://docs.libcs​​.libcpr.org/advanced-cr.orgagecad-angachanc--usage-usage.htmll..html #https-options:〜:text = cpr%3A%3Assloptions%20SSlopts%20%3D%20CPR%3A%3ASSL(SSL%3A%3A%3AACABUFFER%7B%7B%22%2D%2D%2D%2D%2D%2D%2D%2D%2DBEGGIN%20certicate%20certicate%20%2D %2D%2D%2D%2D%5B ...%5D%22%7D)%3B%0ACPR%3A%3A%20R%20R%20%20%20%20CPR%3A%3A%3AGET(CPR%3A%3A%3AAIRL%7b%7B%22Https %3A // www.httpbin.org/get%22%7D%2C%20SSlopts)%3B 在这种情况下,“ Cabuffer”

都会

对此表示赞赏

I am using libcpr for http requests in Visual Studio 2019 IDE. I downloaded it using vcpkg from microsoft. The sample code below is from cpr github page 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 e.g. 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.

Any help would be appreciated!!

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你是我的挚爱i 2025-02-17 00:08:34

在我看来,就像一个版本的问题。 authmode 存在于“ nofollow noreferrer”>最新的header文件,但不存在于版本1.8标头文件,大概是您拥有的。

因此,要么降级代码,要么升级安装。

版本1.8的示例代码为在这里

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.

So, either downgrade your code, or upgrade your installation.

Sample code from version 1.8 is here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文