Sending and receiving HTTP data
Requesting information to an HTTP server is a common task. Here again, the Qt folks prepared some useful classes to make it easy. To achieve this, we will rely on three classes:
QNetworkAccessManager
: This class allows your application to send requests and receive repliesQNetworkRequest
: This class holds the request to be sent with all the information (headers, URL, data, and so on)QNetworkReply
: This class contains the result of aQNetworkRequest
class with the headers and the data
The QNetworkAccessManager
class is the pivot point of the whole Qt HTTP API. It is built around a single QNetworkAccessManager
object that holds the configuration of the client, proxy settings, cache information, and much more. This class is designed to be asynchronous, so you do not need to worry about blocking your current thread.
Let's see it in action in a custom HttpRequest
class. First, the header:
#include <QObject> #include <QNetworkAccessManager>...