This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
requests.h
116 lines (113 loc) · 5.59 KB
/
requests.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#pragma once
#ifndef http996
#define http996
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <fstream>
#include <Windows.h>
#include "wininet.h"
#include "utils.h"
#include "CJsonObject.hpp"
#pragma comment(lib,"wininet.lib")
#pragma comment(lib, "ws2_32.lib")
using namespace std;
typedef unsigned char byte;//
namespace requests{
class BinaryData
{
public:
BinaryData();
explicit BinaryData(int size);
//BinaryData(const BinaryData &);
~BinaryData();
void append(byte n);
void append(byte *buffer, int size);
void append(std::string n);
int find(const char *s);
std::string substr(int start, int end);
void erase(int start, int end);
const byte* raw_buffer();
int size();
std::string to_string();
std::string user_data;
private:
std::vector<byte> data;
};
class Response
{
public:
Response();
Response(std::shared_ptr<BinaryData> rep);
Response(std::string h,std::string origin_domain, std::shared_ptr<BinaryData> data);
~Response();
std::string GetText();
map<std::string,std::string> Header();
const byte*GetBinary();
unsigned int size();
map < std::string, std::string> cookie;
std::vector<std::string> vec_cookie;
std::string req_domain;
std::string operator[](std::string key);
unsigned int status;
private:
map<std::string,std::string> header;
std:: string text;
std::shared_ptr<BinaryData> pContent;
void SplitString(const string& s, vector<string>& v, const string& c);
unsigned int status2int(string &s);
};
class Request
{
public:
Request(std::string url, std::string method,const map<string, string> &header =map<string, string>(),const map<string, string> &options = map<string, string>());
~Request();
string HeaderToString();
void SetPostHeader(BinaryData &data);
std::string url;
std::string domain;
std::string param;
std::string prefix;
unsigned int timeout;
std::string proxy;
map<string, string> header;
map<std::string, std::string> default_options;
int port;
std::string method;
};
class Session{
public:
Session();
Session(std::string proxy);
~Session();
Response Get(std::string url, const map<string, string> &head = map<string, string>(), std::string cookie = "", const map<string, string> &options = map<string, string>());
Response Post(std::string url, map<string, string> &data,const map<string, string> files = map<string, string>(), const map<string, string> &head = map<string, string>(), std::string cookie = "", const map<string, string> &options = map<string, string>());
Response Post(std::string url, BinaryData &data,const map<string, string> &head = map<string, string>(), const map<string, string> &options = map<string, string>());
map<std::string, std::string> cookies;
std::vector<std::string> vec_cookie;
private:
HINTERNET hInternet;
HINTERNET hConnect;
HINTERNET hRequest;
std::string inner_proxy;
private:
bool InstallCookie(Response &r);
};
std::string GetIpByDomainName(const char *szHost);
Response Get(std::string url,const map<string, string> &head = map<string, string>(),std::string cookie="",const map<string, string> &options = map<string, string>());
Response Delete(std::string url, const map<string, string> &head = map<string, string>(), std::string cookie = "", const map<string, string> &options = map<string, string>());
Response Head(std::string url, const map<string, string> &head = map<string, string>(), std::string cookie = "", const map<string, string> &options = map<string, string>());
Response Options(std::string url, const map<string, string> &head = map<string, string>(), std::string cookie = "", const map<string, string> &options = map<string, string>());
Response Put(std::string url, const std::string filepath,const map<string, string> &head = map<string, string>(), std::string cookie = "", const map<string, string> &options = map<string, string>());
Response Post(std::string url, map<string, string> &data, map<string, string> files = map<string, string>(),const map<string, string> &head = map<string, string>(),std::string cookie="",const map<string, string> &options = map<string, string>());
Response Post(std::string url, BinaryData &bin_data,const map<string, string> &head = map<string, string>(),std::string cookie="",const map<string, string> &options = map<string, string>());
Response Post(std::string url, std::string str_data, const map<string, string> &head = map<string, string>(), std::string cookie = "", const map<string, string> &options = map<string, string>());
Response https_post(string url, BinaryData &data,const map<string, string> &head = map<string, string>(),std::string cookie="",const map<string,string> &options = map<string, string>());
Response https_post(string url, map<string, string> &data, map<string, string> files,const map<string, string> &head = map<string, string>(),std::string cookie="",const map<string, string> &options = map<string, string>());
Response request(string method, string url, BinaryData &data,const map<string, string> &head = map<string, string>(),std::string cookie="",const map<string, string> &options = map<string, string>());
Response https_send(string method, string url, int port, DWORD flags, BinaryData &data,const map<string, string> &head = map<string, string>(),std::string cookie="",const map<string, string> &options = map<string, string>());
std::string get_content_type(string &filename);
std::string http_err2str(DWORD code);
}
#endif