[英]using PHP cURL in C++
如何使用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;
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);
任何信息或正確方向的觀點都將是驚人的!
libcurl在BB10上可用,並且已經在sdk中。 不要忘記將LIBS += -lcurl
添加到您的.pro
文件中
他們的網站上有很多例子 。 除了可以從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隱藏了所有底層內容。 將數據轉換為char*
時會感到痛苦。 用întèrnâtioñal數據進行測試。 QNetworkAccessManager
和他的朋友使用完全不同的異步API。 期望使libcurl發揮更大的痛苦。 雖然有一些收獲:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.