-
Notifications
You must be signed in to change notification settings - Fork 6
/
http.h
95 lines (69 loc) · 2.01 KB
/
http.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
90
91
92
93
94
95
#pragma once
#include "encoder.h"
#include "stringext.h"
#include <string>
#include <vector>
#include <map>
#include <winhttp.h>
#pragma comment(lib, "winhttp")
class CWinHttp
{
protected:
HINTERNET m_hSession;
HINTERNET m_hConnect;
HINTERNET m_hRequest;
std::wstring m_strHost;
std::wstring m_strPath;
std::wstring m_strExt;
INTERNET_SCHEME m_nScheme;
INTERNET_PORT m_nPort;
public:
CWinHttp();
//初始化Session
BOOL OpenSession(
const std::string &userAgent = "",
int dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY,
const std::string &proxyName = "",
const std::string &proxyBypass = "",
int dwFlags = 0
);
//连接服务器
BOOL OpenConnect(const std::string &url);
//打开请求
BOOL OpenRequest(bool bPost = false, bool bInitContentType = false);
//发送数据
BOOL Send(LPVOID lpbuffer = NULL, DWORD dwsize = 0);
//上传文件多步提交,写入数据
BOOL Write(LPCVOID lpbuffer, DWORD dwsize);
//获取返回内容
std::vector<BYTE> GetResponseBody();
//获取指定返回协议头
std::string GetResponseHeaderValue(int dwInfoLevel, DWORD dwIndex = WINHTTP_NO_HEADER_INDEX);
std::string GetResponseHeaderValue(const std::string &name);
//获取全部返回协议头
std::string GetResponseHeaders();
//设置请求协议头
BOOL SetRequestHeader(const std::string &name,const std::string &value);
//设置请求referer
BOOL SetReferer(const std::string &referer);
//设置超时时间 OpenSession 以后调用
BOOL SetTimeout(
int nResolveTimeout = 3000,
int nConnectTimeout = 3000,
int nSendTimeout = 3000,
int nReceiveTimeout = 3000
);
//设置属性
BOOL SetOption(int Option, int value);
//是否允许重定向 false不允许 true 允许
BOOL SetLocal(bool Is);
//取重定向地址
std::string GetLocal();
//设置Cookie
BOOL SetCookie(const std::string &cookies);
//获取返回cookies
std::string GetCookie();
//合并Cookies
std::string MergeCookie(const std::string &oldCookies, const std::string &nowCookies);
virtual ~CWinHttp();
};