This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-Qt/doric/plugin/DoricNetworkPlugin.cpp

42 lines
1.2 KiB
C++
Raw Normal View History

2021-04-25 16:44:39 +08:00
#include "DoricNetworkPlugin.h"
#include <QJsonDocument>
#include <QJsonObject>
void DoricNetworkPlugin::request(QString jsValueString, QString callbackId) {
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
QJsonValue jsValue = document.object();
QString url = jsValue["url"].toString();
QString method = jsValue["method"].toString();
QJsonValue headerVal = jsValue["headers"];
QJsonValue dataVal = jsValue["data"];
QJsonValue timeoutVal = jsValue["timeout"];
if (headerVal.isObject()) {
foreach (QString key, headerVal.toObject().keys()) {
httpRequest.setRawHeader(key.toUtf8(),
headerVal[key].toString().toUtf8());
}
}
QObject::connect(&networkAccessManager, SIGNAL(finished(QNetworkReply *)),
this, SLOT(networkRequestFinished(QNetworkReply *)));
if (method == "get") {
httpRequest.setUrl(QUrl(url));
networkAccessManager.get(httpRequest);
}
}
void DoricNetworkPlugin::networkRequestFinished(QNetworkReply *reply) {
int statusCode =
reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (reply->error() == QNetworkReply::NoError) {
} else {
}
reply->deleteLater();
}