Rel*_*lla 1 php c c++ openid libcurl
我决定在我的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;
}
Run Code Online (Sandbox Code Playgroud)
那么..如何将这样的函数转换为PHP的C++(使用libCURL)?