JsonApiJob: Add method usePOST to allow anonymous POST requests

Signed-off-by: Michael Schuster <michael@schuster.ms>
This commit is contained in:
Michael Schuster 2020-01-18 15:03:21 +01:00
parent 2039872ee5
commit 9447a10716
No known key found for this signature in database
GPG key ID: 00819E3BF4177B28
2 changed files with 13 additions and 1 deletions

View file

@ -801,7 +801,7 @@ void JsonApiJob::start()
auto query = _additionalParams;
query.addQueryItem(QLatin1String("format"), QLatin1String("json"));
QUrl url = Utility::concatUrlPath(account()->url(), path(), query);
sendRequest("GET", url, _request);
sendRequest(_usePOST ? "POST" : "GET", url, _request);
AbstractNetworkJob::start();
}

View file

@ -373,6 +373,16 @@ public:
void addQueryParams(const QUrlQuery &params);
void addRawHeader(const QByteArray &headerName, const QByteArray &value);
/**
* @brief usePOST - allow job to do an anonymous POST request instead of GET
* @param params: (optional) true for POST, false for GET (default).
*
* This function needs to be called before start() obviously.
*/
void usePOST(bool usePOST = true) {
_usePOST = usePOST;
}
public slots:
void start() override;
@ -398,6 +408,8 @@ signals:
private:
QUrlQuery _additionalParams;
QNetworkRequest _request;
bool _usePOST = false;
};
/**