libcurl is available on BB10, and it is already in the sdk. Don't forget to add LIBS += -lcurl
to your .pro
file
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.
#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;
}
A few items:
- Curl expects raw data.
QString
s hides all the low level stuff. Expect pain when converting data tochar*
. Do test with întèrnâtioñal data. - This is C, do your homework and understand what is thread friendly and what is not, understand who is responsible for cleaning stuff.
QNetworkAccessManager
and his friends use a completely different API that is asynchronous. Expect incredibly more pain that in making libcurl work. There are some gains though:- Those APIs implements a queue, so you can start an unlimited (like, thousands) number of tasks and Qt/BB10 will throttle requests so you don’t loose connectivity, group request by hosts to save some overhead, …
- Those APIs are mobile-aware: want transfer if 3G or better, no transfer on cell? They can do that.
- These are native Qt API. Work a while with libcurl, you’ll understand.