-
Notifications
You must be signed in to change notification settings - Fork 1
/
request.cpp
60 lines (49 loc) · 1.23 KB
/
request.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "request.h"
Request::Request()
{
}
void Request::setHost(const QString &name)
{
host=name;
}
void Request::setPath(const QString &name)
{
path=name;
}
void Request::setParam(const QString &name,const QString &value)
{
param.insert(name,value);
}
void Request::setoHeader(const QString &name,const QString &value)
{
oHeaders.insert(name,value);
}
void Request::setCookie(const Cookie &a)
{
Cookies.push_back(a);
}
QString Request::getHost()
{return host;}
QString Request::toString()
{
QString x;
QString y;
if(!param.isEmpty()){
for(QMap<QString,QString>::iterator i=param.begin();i!=param.end();++i)
{
if(i==param.begin())y+=QString("?%1=%2").arg(i.key()).arg(i.value());
else y+=QString("&%1=%2").arg(i.key()).arg(i.value());
}
}
x+=QString("%1%2 HTTP/1.1").arg(path).arg(y);
x+=QString("\n");
x+=QString("HOST: %1\n").arg(host);
if(!oHeaders.isEmpty())
for(QMap<QString,QString>::iterator i=oHeaders.begin();i!=oHeaders.end();++i)
x+=QString("%1: %2\r\n").arg(i.key()).arg(i.value());
if(!Cookies.isEmpty())
for(QList<Cookie>::iterator i=Cookies.begin();i!=Cookies.end();++i)
x+=QString("Cookie: %1\n").arg((*i).toString());
x+=("\r\n\r\n");
return x;
}