KanoopProtocolQt 1.2.3
Qt HTTP operations and MQTT client library
Loading...
Searching...
No Matches
httppost.h
1#ifndef HTTPPOST_H
2#define HTTPPOST_H
3#include <Kanoop/http/httpoperation.h>
4#include <Kanoop/serialization/iserializabletojson.h>
5
6/** @brief HTTP POST operation executed asynchronously on a dedicated thread. */
7class LIBKANOOPPROTOCOL_EXPORT HttpPost : public HttpOperation
8{
9 Q_OBJECT
10public:
11 /** @brief Construct an HTTP POST operation with an optional raw body.
12 * @param url The target URL.
13 * @param postBody The raw POST body data. */
14 HttpPost(const QString& url, const QByteArray& postBody = QByteArray()) :
15 HttpOperation(url, Post),
16 _postBody(postBody) {}
17
18 /** @brief Construct an HTTP POST operation with a JSON-serializable body.
19 * @param url The target URL.
20 * @param postBody The object to serialize to JSON for the POST body. */
21 HttpPost(const QString& url, const ISerializableToJson& postBody) :
22 HttpOperation(url, Post),
23 _postBody(postBody.serializeToJson()), _isJson(true) {}
24
25 /** @brief Return the request body data.
26 * @return The POST body as a byte array. */
27 QByteArray requestBody() const { return _postBody; }
28
29protected:
30 /** @brief Execute the HTTP POST request. */
31 virtual void execute() override;
32
33 /** @brief Hook called before the POST request is sent. */
34 virtual void prePostHook() {}
35
36 /** @brief Hook called after the POST reply is received. */
37 virtual void postPostHook() {}
38
39private:
40 QByteArray _postBody;
41 bool _isJson = false;
42};
43
44#endif // HTTPPOST_H
Base class for HTTP operations executed asynchronously on a dedicated thread.
HTTP POST operation executed asynchronously on a dedicated thread.
Definition httppost.h:8
virtual void postPostHook()
Hook called after the POST reply is received.
Definition httppost.h:37
virtual void prePostHook()
Hook called before the POST request is sent.
Definition httppost.h:34
virtual void execute() override
Execute the HTTP POST request.
HttpPost(const QString &url, const ISerializableToJson &postBody)
Construct an HTTP POST operation with a JSON-serializable body.
Definition httppost.h:21
QByteArray requestBody() const
Return the request body data.
Definition httppost.h:27
HttpPost(const QString &url, const QByteArray &postBody=QByteArray())
Construct an HTTP POST operation with an optional raw body.
Definition httppost.h:14