【问题标题】:How to translate such PHP code using CURL into C/C++?如何使用 CURL 将此类 PHP 代码翻译成 C/C++?
【发布时间】:2011-07-17 13:37:19
【问题描述】:

我决定在我的 C++ 服务器中实现 OpenID 登录。我查看了可用的 C++ OpenID 客户端列表,发现只有一个受欢迎的 libopkele。但是对于我的简单服务器来说,它的要求似乎相当多,它有自己的 xml 解析器,对正则表达式使用 boost 等等。

所以我想用 C++ 创建简单的 openID 客户端,所以我决定移植 PHPclient(因为我对 PHPa 有点了解)。有一个名为class.openid.php 的类,它的第一个版本只有 200 行 PHP 代码。我的主要问题是我以前从未在 PHP 和 c++ 中使用过 curl。所以我请求帮助翻译成 C/C++ 这样的 PHP 代码:

function CURL_Request($url, $method="GET", $params = "") { // Remember, SSL MUST BE SUPPORTED
        if (is_array($params)) $params = $this->array2url($params);
        $curl = curl_init($url . ($method == "GET" && $params != "" ? "?" . $params : ""));
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_HTTPGET, ($method == "GET"));
        curl_setopt($curl, CURLOPT_POST, ($method == "POST"));
        if ($method == "POST") curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($curl);

        if (curl_errno($curl) == 0){
            $response;
        }else{
            $this->ErrorStore('OPENID_CURL', curl_error($curl));
        }
        return $response;
}

那么..如何将此类函数从 PHP 转换为 C++(使用 libCURL)?

【问题讨论】:

  • 当然我很想看到一些 php openID 库的完整翻译!比如600行PHP代码(一类)lightopenid。但是没有人为我做过……好吧,我可以自己尝试。因为在我的小型跨平台服务器上使用不小的 libopkele 仅用于 openID 身份验证似乎不适合我。

标签: php c++ c openid libcurl


【解决方案1】:

cURL 有一个 C API:link。你也可以在 C++ 中使用它。

重写你在使用 cURL API 时提供的函数应该不难。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-20
    • 1970-01-01
    • 2011-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多