This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
httprequest.h
89 lines (77 loc) · 2.91 KB
/
httprequest.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef HTTPREQUEST_H
#define HTTPREQUEST_H
#include "media.h"
#include "defines.h"
#include "filesource.h"
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkProxy>
#include <QSharedPointer>
#include <QMap>
typedef QPair<QString, QString> QStringPair;
class HTTPRequest : public QObject
{
Q_OBJECT
public:
HTTPRequest();
void uploadFile(QSharedPointer<Media> media, QString cookie = "", QString username = "", QString password = "");
void put(QString url, QVector<QPair<QString, QString> > fields);
void get(QString url, QVector<QStringPair> params = QVector<QStringPair>());
void post(QString url, QVector<QPair<QString, QString> > fields);
void postFile(QSharedPointer<Media> media, QString cookie = "", QString username = "", QString password = "");
void putFile(QSharedPointer<Media> media, QString cookie = "", QString username = "", QString password = "");
void pause();
void resume();
void stop();
int progress();
void connectProgress(QObject* obj, const char* func);
void connectResult(QObject* obj, const char* func);
void connectError(QObject* obj, const char* func);
enum state { START, END, ERROR, RESUME, PAUSE };
QByteArray userAgent();
qint64 uploaded, doneSize, headerSize;
QString errorString();
QNetworkProxy& getProxy();
bool aborted;
bool failed;
private:
QNetworkAccessManager qnam;
QNetworkReply* reply;
bool inProgress;
void connectReply(const char*);
QString url, getlenurl;
QString cookie, username, password;
QSharedPointer<Media> media;
QVector<QPair<QString, QString> > fields;
QVector<QPair<QString, QString> > formDataFields(QSharedPointer<Media> media, QString cookie = "", QString username = "", QString password = "");
QByteArray formStartPostData(QSharedPointer<Media> media, QString cookie, QString username, QString password);
QPair<QString, QString> getUploadHost(QSharedPointer<Media> media);
void prepareNetworkRequest(QNetworkRequest &inRequest);
QSharedPointer<FileSource> data;
void setProxy();
QNetworkProxy proxy;
bool startRequest(bool emitprogress = true);
QString lastuser, lastcookie, lastpass;
private slots:
void putFile2(QString uploadUrl = "", QString lenUrl = "");
void putFile3();
void putFile4();
void fail(QString msg);
void fail(QNetworkReply::NetworkError code);
void specialFail(QNetworkReply::NetworkError code);
void specialFail2(QNetworkReply::NetworkError ecode);
void putFileProgressReceiver(qint64 done, qint64 total);
void postFileProgressReceiver(qint64 done, qint64 total);
//void progressReceiver(qint64, qint64);
//void statusReceiver(int);
void getReceiver();
void postReceiver();
void postFileReceiver();
signals:
void progress(int);
void status(state);
void result(QString);
void error(QString);
};
#endif // HTTPREQUEST_H