我在 Visual Studio 2019 IDE 中使用 libcpr 處理 http 請求。我使用微軟的 vcpkg 下載了它。下面的示例代碼來自 cpr github 頁面https://github.com/libcpr/cpr#:~:text=#include <,return 0; }
#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”。這個問題不僅僅是這個。還有一些其他的東西會給出類似的錯誤,例如https://docs.libcpr.org/advanced-usage.html# https-options:~:text=cpr::SslOptions sslOpts = cpr::Ssl(ssl::CaBuffer{"-----BEGIN CERTIFICATE-% 2D---[...]"}); cpr::Response r = cpr::Get(cpr::Url{"https% 3A//www.httpbin.org/get"}, sslOpts);在這種情況下“CaBuffer”有同樣的問題。
任何幫助,將不勝感激!!
謝謝
uj5u.com熱心網友回復:
在我看來像一個版本問題。AuthMode存在于最新的頭檔案中,但不存在于1.8版本的頭檔案中,想必是你有的。
所以,要么降級你的代碼,要么升級你的安裝。
1.8 版的示例代碼在這里
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/495533.html
上一篇:為什么這段代碼報告-31大于6?
下一篇:基于條件的前向可變引數
