-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhttp_request.h
64 lines (50 loc) · 1.44 KB
/
http_request.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
Add "network" to .pro
Coded By Virus007
CyberSoldiersST
Email: virus007@protonmail.com
*/
#ifndef HTTP_REQUEST_H
#define HTTP_REQUEST_H
#include <QDebug>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QString>
#include <QEventLoop>
#include <QByteArray>
#include <QVariant>
#include <QLoggingCategory>
//Post http request
/*
Example:
Post("http://google.com/","header1=one&header2=two");
*/
void Post(QString uri, QString header)
{
QLoggingCategory::setFilterRules("qt.network.ssl.warning=false");
QEventLoop eventLoop;
QNetworkAccessManager manager;
QUrl url(uri);
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QObject::connect(&manager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
QNetworkReply *reply = manager.post(request, header.toUtf8());
eventLoop.exec();
qDebug() << "\n";
qDebug() << reply->readAll();
}
void Get(QString uri)
{
QLoggingCategory::setFilterRules("qt.network.ssl.warning=false");
QEventLoop eventLoop;
QNetworkAccessManager mgr;
QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
QUrl url(uri);
QNetworkRequest req(url);
QNetworkReply *reply = mgr.get(req);
eventLoop.exec();
qDebug() << "\n";
qDebug() << reply->readAll();
}
#endif // HTTP_REQUEST_H