-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebRequest.cpp
37 lines (31 loc) · 1 KB
/
WebRequest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "WebRequest.h"
WebRequest::WebRequest (QObject *parent) :
QObject(parent),
manager(new QNetworkAccessManager(this))
{
}
void WebRequest::sendRequest(const QString &url, const QByteArray ¶meter)
{
QNetworkRequest request = QNetworkRequest(QUrl(url));
connect(this->manager, &QNetworkAccessManager::sslErrors, this, &WebRequest::ignoreSSL);
connect(this->manager, &QNetworkAccessManager::finished, this, &WebRequest::replyFinished);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
request.setHeader(QNetworkRequest::ContentLengthHeader, parameter.length());
manager->post(request, parameter);
}
void WebRequest::replyFinished(QNetworkReply* reply)
{
if (reply->error())
{
this->error(reply->error(), reply->errorString());
return;
}
QByteArray arr = reply->readAll();
if (arr.isEmpty())
return;
this->accepted(arr);
}
void WebRequest::ignoreSSL(QNetworkReply *reply, QList<QSslError> error)
{
reply->ignoreSslErrors(error);
}