[英]using PHP cURL in C++
How could I replicate such function in C++ using the BlackBerry Native Library? 如何使用BlackBerry Native Library在C ++中复制此类功能?
$username="admin";
$password="admin";
$url="http://www.yourdomain.com/";
$cookie="cookie.txt";
$postdata = "log=". $username ."&pwd=". $password ."&wp-submit=Log%20In&redirect_to=".
$url ."wp-admin/&testcookie=1";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url . "wp-login.php");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, $url . "wp-admin/");
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
curl_close($ch);
echo $result;
exit;
A Request in the BlackBerry Native Library would usually look like the following as an example : BlackBerry Native Library中的“请求”通常类似于以下示例:
QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager(this);
const QString queryUri = QString::fromLatin1("http://website.com/get.php?email=%1").arg(email);
QNetworkRequest request(queryUri);
QNetworkReply* reply = networkAccessManager->get(request);
Any information or a point in the correct direction would be amazing! 任何信息或正确方向的观点都将是惊人的!
libcurl is available on BB10, and it is already in the sdk. libcurl在BB10上可用,并且已经在sdk中。 Don't forget to add LIBS += -lcurl
to your .pro
file 不要忘记将LIBS += -lcurl
添加到您的.pro
文件中
There's a lot of examples on their site. 他们的网站上有很多例子 。 Save for some options that should translate nicely from your PHP code, it should almost look like that . 除了可以从PHP代码很好地转换的一些选项外 ,它几乎应该像这样 。
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* example.com is redirected, so we tell libcurl to follow redirection */
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
QString
s hides all the low level stuff. QString
s隐藏了所有底层内容。 Expect pain when converting data to char*
. 将数据转换为char*
时会感到痛苦。 Do test with întèrnâtioñal data. 用întèrnâtioñal数据进行测试。 QNetworkAccessManager
and his friends use a completely different API that is asynchronous. QNetworkAccessManager
和他的朋友使用完全不同的异步API。 Expect incredibly more pain that in making libcurl work. 期望使libcurl发挥更大的痛苦。 There are some gains though: 虽然有一些收获:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.