简体   繁体   English

如何将 firebase 与 libcurl 连接

[英]how to connect firebase with libcurl

I want to connect my code to firebase with using libcurl library and read datas i have function like this我想使用 libcurl 库将我的代码连接到 firebase 并读取我有 function 这样的数据

static size_t my_write(void* buffer, size_t size, size_t nmemb, void* param) {
  std::string& text = *static_cast<std::string*>(param);
  size_t totalsize = size * nmemb;
  text.append(static_cast<char*>(buffer), totalsize);
  return totalsize;
}

and I have main function such as我有主要的 function 例如

int main() {



std::string result;
CURL* curl;
CURLcode res;

curl_global_init(CURL_GLOBAL_DEFAULT);

curl = curl_easy_init();
if (curl) {
    curl_easy_setopt(curl,CURLOPT_URL,"https://example-project-62811-default-rtdb.firebaseio.com/.json");

    curl_easy_setopt(curl, CURLOPT_PROXY_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST |
        CURLSSLOPT_NO_REVOKE);
    
    curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,my_write);
    curl_easy_setopt(curl,CURLOPT_WRITEDATA, &result);

    curl_easy_setopt(curl,CURLOPT_VERBOSE, 1L);

    res = curl_easy_perform(curl);

    curl_easy_cleanup(curl);

    if (CURLE_OK != res) {
        std::cerr << "CURL ERROR: " << res << "\n";
    }

}
curl_global_cleanup();

std::cout << result << "\n\n";
}

the code is working fine on other apis like https://api.chucknorris.io and the error that i get for trying to connect firebase is该代码在https://api.chucknorris.io等其他 api 上运行良好,我尝试连接 firebase 时出现的错误是

  • Trying 35.201.97.85:443...尝试 35.201.97.85:443...
  • Connected to example-project-62811-default-rtdb.firebaseio.com (35.201.97.85) port 443 (#0)连接到 example-project-62811-default-rtdb.firebaseio.com (35.201.97.85) 端口 443 (#0)
  • schannel: next InitializeSecurityContext failed: Unknown error (0x80092013) schannel:下一个 InitializeSecurityContext 失败:未知错误(0x80092013)
  • Closing connection 0关闭连接 0
  • schannel: shutting down SSL/TLS connection with example-project-62811-default-rtdb.firebaseio.com port 443 CURL ERROR: 35 schannel:关闭 SSL/TLS 连接与 example-project-62811-default-rtdb.firebaseio.com 端口 443 CURL 错误:35

edit-1 i also tried to write run from command prompt and it gives me same error and when i add add --ssl-no-revoke to script it worked edit-1 我也尝试从命令提示符处编写运行,它给了我同样的错误,当我添加 add --ssl-no-revoke 到脚本时它工作

curl https://example-project-62811-default-rtdb.firebaseio.com/.json --ssl-no-revoke

is working and then i tried to use this technique in my code正在工作,然后我尝试在我的代码中使用这种技术

curl_easy_setopt(curl, CURLOPT_PROXY_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST |
        CURLSSLOPT_NO_REVOKE);

but it didn't work how can i solve this problem?但它没有用我该如何解决这个问题?

Schannel error code 0x80092013 means Revocation Server Offline . Schannel 错误代码0x80092013表示Revocation Server Offline

In your case the Firebase CRL, http://crl.pki.goog/GTS1O1.crl as specified in the server certificate, could not be fetched.在您的情况下,无法获取服务器证书中指定的 Firebase CRL、 http://crl.pki.goog/GTS1O1.crl

That could be due to a misconfiguration of the Windows trust store, DNS, firewall, proxy, corporate network, or alike.这可能是由于 Windows 信任库、DNS、防火墙、代理、公司网络等配置错误。

As a temporary (insecure) solution, you can bypass CRL verification using作为临时(不安全)解决方案,您可以绕过 CRL 验证使用

    curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NO_REVOKE);

Notice the variable - CURLOPT_SSL_OPTIONS .注意变量 - CURLOPT_SSL_OPTIONS The one you try CURLOPT_PROXY_SSL_OPTIONS is for proxy connections only.您尝试的CURLOPT_PROXY_SSL_OPTIONS仅用于代理连接。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM