WindowsAPI编程核心技术-传输技术

TCP

Socket

分配个套接字。

1
2
3
4
5
6
7
8
SOCKET WAAPI Socket(
_In_ int af,
//指定地址族规范
_In_ int type,
//套接字类型
_In_ int protocol
//协议
)//成功返回引用新套接字的描述符 否则返回INVALID_SOCKET并通过WSAGetLastError来获取错误代码

bind

本地地址与套接字绑定。

1
2
3
4
5
6
7
8
int bind(
_In_ SOCKET s,
//标识未绑定套接字的描述符
_In_ const struct sockaddr* name,
//sockaddr结构分配给绑定的套接字
_In_ int namelen
//值的长度
)//成功返回0 否则SOCKET_ERROR

htons

将整数变量从主机字节序转为网络字节序。

1
2
3
4
u_short WSAAPI htons(
_In_ u_short hostshort
//主机字节序
)//网络字节序

inet_addr

点分十进制IP转换为长整数。

1
2
3
unsigned long inet_addr(
_In_ const char* cp
)

listen

将套接字置于正在监听传入连接的状态。

1
2
3
4
5
int listen(
_In_ SOCKET s,
_In_ int backlog
//指定待连接队列的最大长度
)//成功0 否则SOCKET_ERROR

accept

在套接字上尝试连接。

1
2
3
4
5
SOCKET accept(
_In_ SOCKET s,
_Out_ struct sockaddr* addr,
_Inout_ int* addrlen
)

send

在套接字上尝试发送数据。

1
2
3
4
5
6
7
8
9
int send(
_In_ SOCKET s,
_In_ const char* buf,
//要发送的数据缓冲区
_In_ int len,
//长度
_In_ int flags
//调用方式 一般0
)

recv

从连接的或无连接的套接字接收数据。

1
2
3
4
5
6
int recv(
_In_ SOCKET s,
_Out_ char* buf,
_In_ int len,
_In_ int flags
)

例子

服务端:

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
#pragma comment(lib,"ws2_32.lib")
SOCKET g_ServerSocket=NULL,g_ClientSocket=NULL;
VOID CALLBACK RecvThreadProc(VOID) {
sockaddr_in addr = { 0 };
int iLen = sizeof(addr);
g_ClientSocket = ::accept(g_ServerSocket, (sockaddr*)(&addr), &iLen);
char szBuf[MAX_PATH] = { 0 };
while (TRUE) {
int iRet = ::recv(g_ClientSocket, szBuf, MAX_PATH, 0);
if (0 >= iRet)
continue;
printf("%s\n", szBuf);
};
return;
};
BOOL SocketBindAndListen(char* lpszIp, int iPort) {
WSADATA wsaData = { 0 };
::WSAStartup(MAKEWORD(2, 2), &wsaData);
g_ServerSocket = ::socket(AF_INET, SOCK_STREAM, 0);
if (INVALID_SOCKET == g_ServerSocket)
return FALSE;
sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = ::htons(iPort);
addr.sin_addr.S_un.S_addr = ::inet_addr(lpszIp);
if (0 != ::bind(g_ServerSocket, (sockaddr*)(&addr), sizeof(addr)))
return FALSE;
if (0 != ::listen(g_ServerSocket, 1))
return FALSE;
::CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)RecvThreadProc, NULL, NULL, NULL);
return TRUE;
};
VOID SendMsg(char* pszSend) { //接受连接请求后发送信息并关闭套接字
::send(g_ClientSocket, pszSend, (1 + ::lstrlen((LPCWSTR)pszSend)), 0);
printf("%s\n", pszSend);
::closesocket(g_ClientSocket);
::closesocket(g_ServerSocket);
::WSACleanup();
return;
};

客户端:

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
#pragma comment(lib,"ws2_32.lib")
SOCKET g_ServerSocket=NULL,g_ClientSocket=NULL;
VOID CALLBACK RecvThreadProc(VOID) {
char szBuf[MAX_PATH] = { 0 };
while (TRUE) {
int iRet = ::recv(g_ClientSocket, szBuf, MAX_PATH, 0);
if (0 >= iRet)
continue;
printf(szBuf);
};
return;
};
BOOL SocketBindAndListen(char* lpszIp, int iPort) {
WSADATA wsaData = { 0 };
::WSAStartup(MAKEWORD(2, 2), &wsaData);
g_ServerSocket = ::socket(AF_INET, SOCK_STREAM, 0);
if (INVALID_SOCKET == g_ServerSocket)
return FALSE;
sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = ::htons(iPort);
addr.sin_addr.S_un.S_addr = ::inet_addr(lpszIp);
if (0 != ::connect(g_ClientSocket, (sockaddr*)(&addr), sizeof(addr)))
return FALSE;
::CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)RecvThreadProc, NULL, NULL, NULL);
return TRUE;
};
VOID SendMsg(char* pszSend) {
::send(g_ClientSocket, pszSend, (1 + ::lstrlen((LPCWSTR)pszSend)), 0);
::closesocket(g_ClientSocket);
::closesocket(g_ServerSocket);
::WSACleanup();
return;
};

UDP

sendto

发送。

1
2
3
4
5
6
7
8
9
10
int sendto(
_In_ SOCKET s,
_In_ const char* buf,
//要发送的缓冲区
_In_ int len,
//缓冲区大小
_In_ int flags,
_In_ const struct sockaddr* to,
_In_ int tolen
)//成功返回发送的总字节数 否则SOCKET_ERROR

recvfrom

接收数据。

1
2
3
4
5
6
7
8
9
int recvfrom(
_In_ SOCKET s,
_Out_ char* buf,
//传入数据缓冲区
_In_ int len,
_In_ int flags,
_Out_ struct sockaddr* from,
_Inout_opt_ int* fromlen
)//成功返回接受字节数 连接正常关闭返回0 否则返回SOCKET_ERROR

例子

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
#pragma comment(lib,"ws2_32.lib")
SOCKET g_sock = NULL;
BOOL Bind(char* lpszIp, int iPort) {
WSADATA wsaData = { 0 };
::WSAStartup(MAKEWORD(2, 2), &wsaData);
g_sock = ::socket(AF_INET, SOCK_STREAM, 0);
if (INVALID_SOCKET == g_sock)
return FALSE;
sockaddr_in addr = { 0 };
addr.sin_family = AF_INET;
addr.sin_port = ::htons(iPort);
addr.sin_addr.S_un.S_addr = ::inet_addr(lpszIp);
if (0 != ::connect(g_sock, (sockaddr*)(&addr), sizeof(addr)))
return FALSE;
::CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)RecvThreadProc, NULL, NULL, NULL);
return TRUE;
};
VOID SendMsg(char* lpszText,char* lpszIp,int iPort) {
sockaddr_in addr = { 0 };
addr.sin_family = AF_INET;
addr.sin_port = ::htons(iPort);
addr.sin_addr.S_un.S_addr = ::inet_addr(lpszIp);
::sendto(g_sock, lpszText, (1 + ::lstrlen(lpszText)), 0, (sockaddr*)(&addr), sizeof(addr));
return;
};
VOID CALLBACK RecvThreadProc(VOID) {
char szBuf[MAX_PATH] = { 0 };
while (TRUE) {
sockaddr_in addr = { 0 };
int iLen = sizeof(addr);
::recvfrom(g_sock, szBuf, MAX_PATH, 0, (sockaddr*)(&addr), &iLen);
printf("%s\n", szBuf);
};
return;
};

FTP

InternetOpen

初始化一个应用程序。

1
2
3
4
5
6
7
8
9
10
11
12
HINTERNET WINAPI InternetOpen(
_In_ LPCTSTR lpszAgent,
//调用WinInet的应用程序或实体名
_In_ DWORD dwAccessType,
//访问类型 枚举值
_In_ LPCTSTR lpszProxyName,
//代理服务器名
_In_ LPCTSTR lpszProxyBypass,
//可选列表的主机名
_In_ DWORD dwFlags
//选项
)//成功返回句柄 失败NULL

InternetConnect

建立互联网连接。

1
2
3
4
5
6
7
8
9
10
11
12
13
HINTERNET WINAPI InternetConnect(
HINTERNET hInternet,
LPCTSTR lpszServerName,
//连接的主机名和IP
INTERNET_PORT nServerPort,
//端口
LPCTSTR lpszUserName,
LPCTSTR lpszPassword,
DWORD dwService,
//服务类型
DWORD dwFlags,
DWORD dwContext
)//成功非0 失败0且需要InternetCloseHandle释放

FtpOpenFile

访问FTP远程服务器上远程文件,可读写。

1
2
3
4
5
6
7
8
9
HINTERNET WINAPI FtpOpenFile(
_In_ HINTERNET hConnect,
_In_ LPCTSTR lpszFileName,
//要访问的文件名
_In_ DWORD dwAccess,
//文件访问 读写二选一
_In_ DWORD dwFlags,
_In_ DWORD_PTR dwContext
)//成功句柄 失败NULL

InternetWriteFile

远程写。

1
2
3
4
5
6
7
8
9
BOOL WINAPI InternetWriteFile(
_In_ HINTERNET hFile,
_Out_ LPVOID lpBuffer,
//缓冲区指针
_In_ DWORD dwNumberOfBytesToRead,
//写入数据字节量
_Out_ LPDWORD lpdwNumberOfBytesRead
//接收写入字节量
)//成功TRUE 失败FALSE

InternetReadFile

1
2
3
4
5
6
7
8
9
BOOL WINAPI InternetReadFile(
_In_ HINTERNET hFile,
_Out_ LPVOID lpBuffer,
//缓冲区
_In_ DWORD dwNumberOfBytesToRead,
//欲读取的字节量
_Out_ LPDWORD lpdwNumberOfBytesRead
//实际读取字节量
) //成功TRUE 失败FALSE

例子

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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <WinInet.h>
#pragma comment(lib,"ws2_32.lib")
BOOL Ftp_UrlCrack(PWCHAR pszUrl, PWCHAR pszScheme, PWCHAR pszHostName, PWCHAR pszUserName, PWCHAR pszPassword, PWCHAR pszUrlPath, PWCHAR pszExtraInfo, DWORD dwBufferSize) {
BOOL bRet = FALSE;
URL_COMPONENTS uc = { 0 };
::RtlZeroMemory(&uc, sizeof(uc));
::RtlZeroMemory(pszScheme, dwBufferSize);
::RtlZeroMemory(pszHostName, dwBufferSize);
::RtlZeroMemory(pszUserName, dwBufferSize);
::RtlZeroMemory(pszPassword, dwBufferSize);
::RtlZeroMemory(pszUrlPath, dwBufferSize);
::RtlZeroMemory(pszExtraInfo, dwBufferSize);
uc.dwStructSize = sizeof(uc);
uc.dwSchemeLength = dwBufferSize - 1;
uc.dwHostNameLength = dwBufferSize - 1;
uc.dwUserNameLength = dwBufferSize - 1;
uc.dwPasswordLength = dwBufferSize - 1;
uc.dwUrlPathLength = dwBufferSize - 1;
uc.dwExtraInfoLength = dwBufferSize - 1;
uc.lpszScheme = pszScheme;
uc.lpszHostName = pszHostName;
uc.lpszUserName = pszUserName;
uc.lpszPassword = pszPassword;
uc.lpszUrlPath = pszUrlPath;
uc.lpszExtraInfo = pszExtraInfo;
bRet = ::InternetCrackUrl(pszUrl, 0, 0, &uc);
return bRet;
};
BOOL Ftp_SaveToFile(PWCHAR pszFileName, PBYTE pData, DWORD dwDataSize) {
HANDLE hFile = ::CreateFile(pszFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL);
if (INVALID_HANDLE_VALUE == hFile)
return FALSE;
DWORD dwRet = 0;
::WriteFile(hFile, pData, dwDataSize, &dwRet, NULL);
::CloseHandle(hFile);
return TRUE;
};
BOOL FTPDownload(PWCHAR pszDownloadUrl, PBYTE* ppDownloadData, PDWORD pdwDownloadDataSize) {
WCHAR szScheme[MAX_PATH] = { 0 };
WCHAR szHostName[MAX_PATH] = { 0 };
WCHAR szUserName[MAX_PATH] = { 0 };
WCHAR szPassword[MAX_PATH] = { 0 };
WCHAR szUrlPath[MAX_PATH] = { 0 };
WCHAR szExtraInfo[MAX_PATH] = { 0 };
::RtlZeroMemory(szScheme, MAX_PATH);
::RtlZeroMemory(szHostName, MAX_PATH);
::RtlZeroMemory(szUserName, MAX_PATH);
::RtlZeroMemory(szPassword, MAX_PATH);
::RtlZeroMemory(szUrlPath, MAX_PATH);
::RtlZeroMemory(szExtraInfo, MAX_PATH);
if (FALSE == Ftp_UrlCrack(pszDownloadUrl, szScheme, szHostName, szUserName, szPassword, szUrlPath, szExtraInfo, MAX_PATH))
return FALSE;
if (0 < ::lstrlen(szExtraInfo))
::lstrcat(szUrlPath, szExtraInfo);
HINTERNET hInternet = NULL;
HINTERNET hConnect = NULL;
HINTERNET hFTPFile = NULL;
PBYTE pDownloadData = NULL;
DWORD dwDownloadDataSize = 0;
DWORD dwBufferSize = 4096;
PBYTE pBuf = NULL;
DWORD dwBytesReturn = 0;
DWORD dwOffset = 0;
BOOL bRet = FALSE;
do {
hInternet = ::InternetOpen(L"WinInet Ftp Download V1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (NULL == hInternet)
break;
hConnect = ::InternetConnect(hInternet, szHostName, INTERNET_INVALID_PORT_NUMBER, szUserName, szPassword, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
if (NULL == hConnect)
break;
hFTPFile = ::FtpOpenFile(hConnect, szUrlPath, GENERIC_READ, FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_RELOAD, NULL);
if (NULL == hFTPFile)
break;
dwDownloadDataSize = ::FtpGetFileSize(hFTPFile, NULL);
pDownloadData = new BYTE[dwDownloadDataSize];
if (NULL == pDownloadData)
break;
::RtlZeroMemory(pDownloadData, dwDownloadDataSize);
pBuf = new BYTE[dwBufferSize];
if (NULL == pBuf)
break;
::RtlZeroMemory(pBuf, dwBufferSize);
do {
bRet = ::InternetReadFile(hFTPFile, pBuf, dwBufferSize, &dwBytesReturn);
if (FALSE == bRet)
break;
::RtlCopyMemory((pDownloadData + dwOffset), pBuf, dwBytesReturn);
dwOffset = dwOffset + dwBytesReturn;
} while (dwDownloadDataSize > dwOffset);
} while (FALSE);
if (FALSE == bRet){
delete[]pDownloadData;
pDownloadData = NULL;
dwDownloadDataSize = 0;
}
*ppDownloadData = pDownloadData;
*pdwDownloadDataSize = dwDownloadDataSize;
if (NULL != pBuf){
delete[]pBuf;
pBuf = NULL;
}
if (NULL != hFTPFile)
::InternetCloseHandle(hFTPFile);
if (NULL != hConnect)
::InternetCloseHandle(hConnect);
if (NULL != hInternet)
::InternetCloseHandle(hInternet);
return bRet;
};
BOOL FTPUpload(PWCHAR pszUploadUrl, PBYTE pUploadData, DWORD dwUploadDataSize) {
WCHAR szScheme[MAX_PATH] = { 0 };
WCHAR szHostName[MAX_PATH] = { 0 };
WCHAR szUserName[MAX_PATH] = { 0 };
WCHAR szPassword[MAX_PATH] = { 0 };
WCHAR szUrlPath[MAX_PATH] = { 0 };
WCHAR szExtraInfo[MAX_PATH] = { 0 };
::RtlZeroMemory(szScheme, MAX_PATH);
::RtlZeroMemory(szHostName, MAX_PATH);
::RtlZeroMemory(szUserName, MAX_PATH);
::RtlZeroMemory(szPassword, MAX_PATH);
::RtlZeroMemory(szUrlPath, MAX_PATH);
::RtlZeroMemory(szExtraInfo, MAX_PATH);
if (FALSE == Ftp_UrlCrack(pszUploadUrl, szScheme, szHostName, szUserName, szPassword, szUrlPath, szExtraInfo, MAX_PATH))
return FALSE;
if (0 < ::lstrlen(szExtraInfo))
::lstrcat(szUrlPath, szExtraInfo);
HINTERNET hInternet = NULL;
HINTERNET hConnect = NULL;
HINTERNET hFTPFile = NULL;
DWORD dwBytesReturn = 0;
BOOL bRet = FALSE;
do {
hInternet = ::InternetOpen(L"WinInet Ftp Upload V1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (NULL == hInternet)
break;
hConnect = ::InternetConnect(hInternet, szHostName, INTERNET_INVALID_PORT_NUMBER, szUserName, szPassword, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
if (NULL == hConnect)
break;
hFTPFile = ::FtpOpenFile(hConnect, szUrlPath, GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_RELOAD, NULL);
if (NULL == hFTPFile)
break;
bRet = ::InternetWriteFile(hFTPFile, pUploadData, dwUploadDataSize, &dwBytesReturn);
if (FALSE == bRet)
break;
} while (FALSE);
if (NULL != hFTPFile)
::InternetCloseHandle(hFTPFile);
if (NULL != hConnect)
::InternetCloseHandle(hConnect);
if (NULL != hInternet)
::InternetCloseHandle(hInternet);
return bRet;
};

HTTP

HttpOpenRequest

创建一个HTTP请求句柄。

1
2
3
4
5
6
7
8
9
10
11
HINTERNET HttpOpenRequest(
_In_ HINTERNET hConnect,
_In_ LPCTSTR lpszVerb,
//请求需要用的动词
_In_ LPCTSTR lpszObjectName,
_In_ LPCTSTR lpszVersion,
_In_ LPCTSTR lpszReferer,
_In_ LPCTSTR* lplpszAcceptTypes,
_In_ DWORD dwFlags,
_In_ DWORD_PTR dwContext
)//成功句柄 否则NULL

HttpSendRequestEx

指定请求发送到HTTP服务器。

1
2
3
4
5
6
7
BOOL HttpSendRequestEx(
_In_ HINTERNET hRequest,
_In_ LPINTERNET_BUFFERS lpBuffersIn,
_Out_ LPINTERNET_BUFFERS lpBuffersOut,
_In_ DWORD dwFlags,
_In_ DWORD_PTR dwContext
)//成功TRUE 失败FALSE

HttpQueryInfo

查询HTTP请求信息。

1
2
3
4
5
6
7
8
9
BOOL WINAPI HttpQueryInfo(
_In_ HINTERNET hRequest,
_In_ DWORD dwInfoLevel,
_Inout_ LPVOID lpBuffer,
//接收信息的缓冲区
_Inout_ LPDWORD lpdwBufferLength,
//缓冲区长度值
_Inout_ LPDWORD lpdwIndex
)//成功TRUE 失败FALSE

例子

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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#include <WinInet.h>
#pragma comment(lib,"ws2_32.lib")
using namespace std;
BOOL Http_UrlCrack(PWCHAR pszUrl, PWCHAR pszScheme, PWCHAR pszHostName, PWCHAR pszUserName, PWCHAR pszPassword, PWCHAR pszUrlPath, PWCHAR pszExtraInfo, DWORD dwBufferSize) {
BOOL bRet = FALSE;
URL_COMPONENTS uc = { 0 };
::RtlZeroMemory(&uc, sizeof(uc));
::RtlZeroMemory(pszScheme, dwBufferSize);
::RtlZeroMemory(pszHostName, dwBufferSize);
::RtlZeroMemory(pszUserName, dwBufferSize);
::RtlZeroMemory(pszPassword, dwBufferSize);
::RtlZeroMemory(pszUrlPath, dwBufferSize);
::RtlZeroMemory(pszExtraInfo, dwBufferSize);
uc.dwStructSize = sizeof(uc);
uc.dwSchemeLength = dwBufferSize - 1;
uc.dwHostNameLength = dwBufferSize - 1;
uc.dwUserNameLength = dwBufferSize - 1;
uc.dwPasswordLength = dwBufferSize - 1;
uc.dwUrlPathLength = dwBufferSize - 1;
uc.dwExtraInfoLength = dwBufferSize - 1;
uc.lpszScheme = pszScheme;
uc.lpszHostName = pszHostName;
uc.lpszUserName = pszUserName;
uc.lpszPassword = pszPassword;
uc.lpszUrlPath = pszUrlPath;
uc.lpszExtraInfo = pszExtraInfo;
bRet = ::InternetCrackUrl(pszUrl, 0, 0, &uc);
return bRet;
};
BOOL Ftp_SaveToFile(PWCHAR pszFileName, PBYTE pData, DWORD dwDataSize) {
HANDLE hFile = ::CreateFile(pszFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL);
if (INVALID_HANDLE_VALUE == hFile)
return FALSE;
DWORD dwRet = 0;
::WriteFile(hFile, pData, dwDataSize, &dwRet, NULL);
::CloseHandle(hFile);
return TRUE;
};
BOOL Http_GetContentLength(char* pResponseHeader, PDWORD pdwContentLength) {// 从Content-Length获取数据长度
int i = 0;
char szContentLength[MAX_PATH] = { 0 };
DWORD dwContentLength = 0;
char szSubStr[] = "Content-Length: ";
::RtlZeroMemory(szContentLength, MAX_PATH);
char* p = ::strstr(pResponseHeader, szSubStr);
if (NULL == p)
return FALSE;
p = p + ::lstrlen((LPCWSTR)szSubStr);
while (('0' <= *p) && ('9' >= *p)) {
szContentLength[i] = *p;
p++;
i++;
};
dwContentLength = ::atoi(szContentLength);
*pdwContentLength = dwContentLength;
return TRUE;
};
BOOL Http_Download(PWCHAR pszDownloadUrl, BYTE** ppDownloadData, DWORD* pdwDownloadDataSize) {
WCHAR szScheme[MAX_PATH] = { 0 };
WCHAR szHostName[MAX_PATH] = { 0 };
WCHAR szUserName[MAX_PATH] = { 0 };
WCHAR szPassword[MAX_PATH] = { 0 };
WCHAR szUrlPath[MAX_PATH] = { 0 };
WCHAR szExtraInfo[MAX_PATH] = { 0 };
::RtlZeroMemory(szScheme, MAX_PATH);
::RtlZeroMemory(szHostName, MAX_PATH);
::RtlZeroMemory(szUserName, MAX_PATH);
::RtlZeroMemory(szPassword, MAX_PATH);
::RtlZeroMemory(szUrlPath, MAX_PATH);
::RtlZeroMemory(szExtraInfo, MAX_PATH);
if (FALSE == Http_UrlCrack(pszDownloadUrl, szScheme, szHostName, szUserName, szPassword, szUrlPath, szExtraInfo, MAX_PATH))
return FALSE;
HINTERNET hInternet = NULL;
HINTERNET hConnect = NULL;
HINTERNET hRequest = NULL;
DWORD dwOpenRequestFlags = 0;
BOOL bRet = FALSE;
unsigned char* pResponseHeaderIInfo = NULL;
DWORD dwResponseHeaderIInfoSize = 2048;
PBYTE pBuf = NULL;
DWORD dwBufSize = 64 * 1024;
PBYTE pDownloadData = NULL;
DWORD dwDownloadDataSize = 0;
DWORD dwRet = 0;
DWORD dwOffset = 0;
do {
hInternet = ::InternetOpen(L"WinInetGet/0.1", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (NULL == hInternet)
break;
hConnect = ::InternetConnect(hInternet, szHostName, INTERNET_DEFAULT_HTTP_PORT, szUserName, szPassword, INTERNET_SERVICE_HTTP, 0, 0);
if (NULL == hConnect)
break;
dwOpenRequestFlags = INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP |
INTERNET_FLAG_KEEP_CONNECTION |
INTERNET_FLAG_NO_AUTH |
INTERNET_FLAG_NO_COOKIES |
INTERNET_FLAG_NO_UI |
INTERNET_FLAG_RELOAD;
if (0 < ::lstrlen(szExtraInfo))
::lstrcat(szUrlPath, szExtraInfo);
hRequest = ::HttpOpenRequest(hConnect, L"GET", szUrlPath, NULL, NULL, NULL, dwOpenRequestFlags, 0);
if (NULL == hRequest)
break;
bRet = ::HttpSendRequest(hRequest, NULL, 0, NULL, 0);
if (FALSE == bRet)
break;
pResponseHeaderIInfo = new unsigned char[dwResponseHeaderIInfoSize];
if (NULL == pResponseHeaderIInfo)
break;
::RtlZeroMemory(pResponseHeaderIInfo, dwResponseHeaderIInfoSize);
bRet = ::HttpQueryInfo(hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, pResponseHeaderIInfo, &dwResponseHeaderIInfoSize, NULL);
if (FALSE == bRet)
break;
printf("[HTTP_Download_ResponseHeaderIInfo]\n\n%s\n\n", pResponseHeaderIInfo);
bRet = Http_GetContentLength((char*)pResponseHeaderIInfo, &dwDownloadDataSize);
if (FALSE == bRet)
break;
pBuf = new BYTE[dwBufSize];
if (NULL == pBuf)
break;
pDownloadData = new BYTE[dwDownloadDataSize];
if (NULL == pDownloadData)
break;
::RtlZeroMemory(pDownloadData, dwDownloadDataSize);
do {
::RtlZeroMemory(pBuf, dwBufSize);
bRet = ::InternetReadFile(hRequest, pBuf, dwBufSize, &dwRet);
if (FALSE == bRet)
break;
::RtlCopyMemory((pDownloadData + dwOffset), pBuf, dwRet);
dwOffset = dwOffset + dwRet;
} while (dwDownloadDataSize > dwOffset);
*ppDownloadData = pDownloadData;
*pdwDownloadDataSize = dwDownloadDataSize;
} while (FALSE);
if (NULL != pBuf) {
delete[]pBuf;
pBuf = NULL;
};
if (NULL != pResponseHeaderIInfo) {
delete[]pResponseHeaderIInfo;
pResponseHeaderIInfo = NULL;
};
if (NULL != hRequest) {
::InternetCloseHandle(hRequest);
hRequest = NULL;
};
if (NULL != hConnect) {
::InternetCloseHandle(hConnect);
hConnect = NULL;
};
if (NULL != hInternet) {
::InternetCloseHandle(hInternet);
hInternet = NULL;
};
return bRet;
};
BOOL Http_Upload(PWCHAR pszUploadUrl, BYTE* pUploadData, DWORD dwUploadDataSize){
WCHAR szScheme[MAX_PATH] = { 0 };
WCHAR szHostName[MAX_PATH] = { 0 };
WCHAR szUserName[MAX_PATH] = { 0 };
WCHAR szPassword[MAX_PATH] = { 0 };
WCHAR szUrlPath[MAX_PATH] = { 0 };
WCHAR szExtraInfo[MAX_PATH] = { 0 };
::RtlZeroMemory(szScheme, MAX_PATH);
::RtlZeroMemory(szHostName, MAX_PATH);
::RtlZeroMemory(szUserName, MAX_PATH);
::RtlZeroMemory(szPassword, MAX_PATH);
::RtlZeroMemory(szUrlPath, MAX_PATH);
::RtlZeroMemory(szExtraInfo, MAX_PATH);
if (FALSE == Http_UrlCrack(pszUploadUrl, szScheme, szHostName, szUserName, szPassword, szUrlPath, szExtraInfo, MAX_PATH))
return FALSE;
HINTERNET hInternet = NULL;
HINTERNET hConnect = NULL;
HINTERNET hRequest = NULL;
DWORD dwOpenRequestFlags = 0;
BOOL bRet = FALSE;
DWORD dwRet = 0;
unsigned char* pResponseHeaderIInfo = NULL;
DWORD dwResponseHeaderIInfoSize = 2048;
PBYTE pBuf = NULL;
DWORD dwBufSize = 64 * 1024;
PBYTE pResponseBodyData = NULL;
DWORD dwResponseBodyDataSize = 0;
DWORD dwOffset = 0;
DWORD dwPostDataSize = dwUploadDataSize;
INTERNET_BUFFERS internetBuffers = { 0 };
do{
hInternet = ::InternetOpen(L"WinInetPost/0.1", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (NULL == hInternet)
break;
hConnect = ::InternetConnect(hInternet, szHostName, INTERNET_DEFAULT_HTTP_PORT, szUserName, szPassword, INTERNET_SERVICE_HTTP, 0, 0);
if (NULL == hConnect)
break;
dwOpenRequestFlags = INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP |
INTERNET_FLAG_KEEP_CONNECTION |
INTERNET_FLAG_NO_AUTH |
INTERNET_FLAG_NO_COOKIES |
INTERNET_FLAG_NO_UI |
INTERNET_FLAG_RELOAD;
if (0 < ::lstrlen(szExtraInfo))
::lstrcat(szUrlPath, szExtraInfo);
hRequest = ::HttpOpenRequest(hConnect, L"POST", szUrlPath, NULL, NULL, NULL, dwOpenRequestFlags, 0);
if (NULL == hRequest)
break;
::RtlZeroMemory(&internetBuffers, sizeof(internetBuffers));
internetBuffers.dwStructSize = sizeof(internetBuffers);
internetBuffers.dwBufferTotal = dwPostDataSize;
bRet = ::HttpSendRequestEx(hRequest, &internetBuffers, NULL, 0, 0);
if (FALSE == bRet)
break;
bRet = ::InternetWriteFile(hRequest, pUploadData, dwUploadDataSize, &dwRet);
if (FALSE == bRet)
break;
bRet = ::HttpEndRequest(hRequest, NULL, 0, 0);
if (FALSE == bRet)
break;
pResponseHeaderIInfo = new unsigned char[dwResponseHeaderIInfoSize];
if (NULL == pResponseHeaderIInfo)
break;
::RtlZeroMemory(pResponseHeaderIInfo, dwResponseHeaderIInfoSize);
bRet = ::HttpQueryInfo(hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, pResponseHeaderIInfo, &dwResponseHeaderIInfoSize, NULL);
if (FALSE == bRet)
break;
printf("[HTTP_Upload_ResponseHeaderIInfo]\n\n%s\n\n", pResponseHeaderIInfo);
bRet = Http_GetContentLength((char*)pResponseHeaderIInfo, &dwResponseBodyDataSize);
if (FALSE == bRet)
break;
pBuf = new BYTE[dwBufSize];
if (NULL == pBuf)
break;
pResponseBodyData = new BYTE[dwResponseBodyDataSize];
if (NULL == pResponseBodyData)
break;
::RtlZeroMemory(pResponseBodyData, dwResponseBodyDataSize);
do{
::RtlZeroMemory(pBuf, dwBufSize);
bRet = ::InternetReadFile(hRequest, pBuf, dwBufSize, &dwRet);
if (FALSE == bRet)
break;
::RtlCopyMemory((pResponseBodyData + dwOffset), pBuf, dwRet);
dwOffset = dwOffset + dwRet;
} while (dwResponseBodyDataSize > dwOffset);
} while (FALSE);
if (NULL != pResponseBodyData) {
delete[]pResponseBodyData;
pResponseBodyData = NULL;
};
if (NULL != pBuf) {
delete[]pBuf;
pBuf = NULL;
};
if (NULL != pResponseHeaderIInfo) {
delete[]pResponseHeaderIInfo;
pResponseHeaderIInfo = NULL;
};
if (NULL != hRequest) {
::InternetCloseHandle(hRequest);
hRequest = NULL;
};
if (NULL != hConnect) {
::InternetCloseHandle(hConnect);
hConnect = NULL;
};
if (NULL != hInternet) {
::InternetCloseHandle(hInternet);
hInternet = NULL;
};
return bRet;
};

HTTPS

跟HTTP差不多,不讲了。

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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#include <WinInet.h>
#pragma comment(lib,"ws2_32.lib")
using namespace std;
BOOL Http_UrlCrack(PWCHAR pszUrl, PWCHAR pszScheme, PWCHAR pszHostName, PWCHAR pszUserName, PWCHAR pszPassword, PWCHAR pszUrlPath, PWCHAR pszExtraInfo, DWORD dwBufferSize) {
BOOL bRet = FALSE;
URL_COMPONENTS uc = { 0 };
::RtlZeroMemory(&uc, sizeof(uc));
::RtlZeroMemory(pszScheme, dwBufferSize);
::RtlZeroMemory(pszHostName, dwBufferSize);
::RtlZeroMemory(pszUserName, dwBufferSize);
::RtlZeroMemory(pszPassword, dwBufferSize);
::RtlZeroMemory(pszUrlPath, dwBufferSize);
::RtlZeroMemory(pszExtraInfo, dwBufferSize);
uc.dwStructSize = sizeof(uc);
uc.dwSchemeLength = dwBufferSize - 1;
uc.dwHostNameLength = dwBufferSize - 1;
uc.dwUserNameLength = dwBufferSize - 1;
uc.dwPasswordLength = dwBufferSize - 1;
uc.dwUrlPathLength = dwBufferSize - 1;
uc.dwExtraInfoLength = dwBufferSize - 1;
uc.lpszScheme = pszScheme;
uc.lpszHostName = pszHostName;
uc.lpszUserName = pszUserName;
uc.lpszPassword = pszPassword;
uc.lpszUrlPath = pszUrlPath;
uc.lpszExtraInfo = pszExtraInfo;
bRet = ::InternetCrackUrl(pszUrl, 0, 0, &uc);
return bRet;
};
BOOL Http_GetContentLength(char* pResponseHeader, PDWORD pdwContentLength) {// 从Content-Length获取数据长度
int i = 0;
char szContentLength[MAX_PATH] = { 0 };
DWORD dwContentLength = 0;
char szSubStr[] = "Content-Length: ";
::RtlZeroMemory(szContentLength, MAX_PATH);
char* p = ::strstr(pResponseHeader, szSubStr);
if (NULL == p)
return FALSE;
p = p + ::lstrlen((LPCWSTR)szSubStr);
while (('0' <= *p) && ('9' >= *p)) {
szContentLength[i] = *p;
p++;
i++;
};
dwContentLength = ::atoi(szContentLength);
*pdwContentLength = dwContentLength;
return TRUE;
};
BOOL Http_Download(PWCHAR pszDownloadUrl, BYTE** ppDownloadData, DWORD* pdwDownloadDataSize) {
WCHAR szScheme[MAX_PATH] = { 0 };
WCHAR szHostName[MAX_PATH] = { 0 };
WCHAR szUserName[MAX_PATH] = { 0 };
WCHAR szPassword[MAX_PATH] = { 0 };
WCHAR szUrlPath[MAX_PATH] = { 0 };
WCHAR szExtraInfo[MAX_PATH] = { 0 };
::RtlZeroMemory(szScheme, MAX_PATH);
::RtlZeroMemory(szHostName, MAX_PATH);
::RtlZeroMemory(szUserName, MAX_PATH);
::RtlZeroMemory(szPassword, MAX_PATH);
::RtlZeroMemory(szUrlPath, MAX_PATH);
::RtlZeroMemory(szExtraInfo, MAX_PATH);
if (FALSE == Http_UrlCrack(pszDownloadUrl, szScheme, szHostName, szUserName, szPassword, szUrlPath, szExtraInfo, MAX_PATH))
return FALSE;
HINTERNET hInternet = NULL;
HINTERNET hConnect = NULL;
HINTERNET hRequest = NULL;
DWORD dwOpenRequestFlags = 0;
BOOL bRet = FALSE;
unsigned char* pResponseHeaderIInfo = NULL;
DWORD dwResponseHeaderIInfoSize = 2048;
PBYTE pBuf = NULL;
DWORD dwBufSize = 64 * 1024;
PBYTE pDownloadData = NULL;
DWORD dwDownloadDataSize = 0;
DWORD dwRet = 0;
DWORD dwOffset = 0;
do {
hInternet = ::InternetOpen(L"WinInetGet/0.1", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (NULL == hInternet)
break;
hConnect = ::InternetConnect(hInternet, szHostName, INTERNET_DEFAULT_HTTPS_PORT, szUserName, szPassword, INTERNET_SERVICE_HTTP, 0, 0);
if (NULL == hConnect)
break;
dwOpenRequestFlags = INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP |
INTERNET_FLAG_KEEP_CONNECTION |
INTERNET_FLAG_NO_AUTH |
INTERNET_FLAG_NO_COOKIES |
INTERNET_FLAG_NO_UI |
INTERNET_FLAG_RELOAD |
INTERNET_FLAG_SECURE |
INTERNET_FLAG_IGNORE_CERT_CN_INVALID; //忽略无效证书
if (0 < ::lstrlen(szExtraInfo))
::lstrcat(szUrlPath, szExtraInfo);
hRequest = ::HttpOpenRequest(hConnect, L"GET", szUrlPath, NULL, NULL, NULL, dwOpenRequestFlags, 0);
if (NULL == hRequest)
break;
DWORD dwFlags = dwFlags | SECURITY_FLAG_IGNORE_UNKNOWN_CA; //忽略未知CA
::InternetSetOption(hRequest, INTERNET_OPTION_SECURITY_FLAGS,&dwFlags, sizeof(dwFlags));
bRet = ::HttpSendRequest(hRequest, NULL, 0, NULL, 0);
if (FALSE == bRet)
break;
pResponseHeaderIInfo = new unsigned char[dwResponseHeaderIInfoSize];
if (NULL == pResponseHeaderIInfo)
break;
::RtlZeroMemory(pResponseHeaderIInfo, dwResponseHeaderIInfoSize);
bRet = ::HttpQueryInfo(hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, pResponseHeaderIInfo, &dwResponseHeaderIInfoSize, NULL);
if (FALSE == bRet)
break;
printf("[HTTP_Download_ResponseHeaderIInfo]\n\n%s\n\n", pResponseHeaderIInfo);
bRet = Http_GetContentLength((char*)pResponseHeaderIInfo, &dwDownloadDataSize);
if (FALSE == bRet)
break;
pBuf = new BYTE[dwBufSize];
if (NULL == pBuf)
break;
pDownloadData = new BYTE[dwDownloadDataSize];
if (NULL == pDownloadData)
break;
::RtlZeroMemory(pDownloadData, dwDownloadDataSize);
do {
::RtlZeroMemory(pBuf, dwBufSize);
bRet = ::InternetReadFile(hRequest, pBuf, dwBufSize, &dwRet);
if (FALSE == bRet)
break;
::RtlCopyMemory((pDownloadData + dwOffset), pBuf, dwRet);
dwOffset = dwOffset + dwRet;
} while (dwDownloadDataSize > dwOffset);
*ppDownloadData = pDownloadData;
*pdwDownloadDataSize = dwDownloadDataSize;
} while (FALSE);
if (NULL != pBuf) {
delete[]pBuf;
pBuf = NULL;
};
if (NULL != pResponseHeaderIInfo) {
delete[]pResponseHeaderIInfo;
pResponseHeaderIInfo = NULL;
};
if (NULL != hRequest) {
::InternetCloseHandle(hRequest);
hRequest = NULL;
};
if (NULL != hConnect) {
::InternetCloseHandle(hConnect);
hConnect = NULL;
};
if (NULL != hInternet) {
::InternetCloseHandle(hInternet);
hInternet = NULL;
};
return bRet;
};
BOOL Http_Upload(PWCHAR pszUploadUrl, BYTE* pUploadData, DWORD dwUploadDataSize) {
WCHAR szScheme[MAX_PATH] = { 0 };
WCHAR szHostName[MAX_PATH] = { 0 };
WCHAR szUserName[MAX_PATH] = { 0 };
WCHAR szPassword[MAX_PATH] = { 0 };
WCHAR szUrlPath[MAX_PATH] = { 0 };
WCHAR szExtraInfo[MAX_PATH] = { 0 };
::RtlZeroMemory(szScheme, MAX_PATH);
::RtlZeroMemory(szHostName, MAX_PATH);
::RtlZeroMemory(szUserName, MAX_PATH);
::RtlZeroMemory(szPassword, MAX_PATH);
::RtlZeroMemory(szUrlPath, MAX_PATH);
::RtlZeroMemory(szExtraInfo, MAX_PATH);
if (FALSE == Http_UrlCrack(pszUploadUrl, szScheme, szHostName, szUserName, szPassword, szUrlPath, szExtraInfo, MAX_PATH))
return FALSE;
HINTERNET hInternet = NULL;
HINTERNET hConnect = NULL;
HINTERNET hRequest = NULL;
DWORD dwOpenRequestFlags = 0;
BOOL bRet = FALSE;
DWORD dwRet = 0;
unsigned char* pResponseHeaderIInfo = NULL;
DWORD dwResponseHeaderIInfoSize = 2048;
PBYTE pBuf = NULL;
DWORD dwBufSize = 64 * 1024;
PBYTE pResponseBodyData = NULL;
DWORD dwResponseBodyDataSize = 0;
DWORD dwOffset = 0;
DWORD dwPostDataSize = dwUploadDataSize;
INTERNET_BUFFERS internetBuffers = { 0 };
do {
hInternet = ::InternetOpen(L"WinInetPost/0.1", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (NULL == hInternet)
break;
hConnect = ::InternetConnect(hInternet, szHostName, INTERNET_DEFAULT_HTTPS_PORT, szUserName, szPassword, INTERNET_SERVICE_HTTP, 0, 0);
if (NULL == hConnect)
break;
dwOpenRequestFlags = INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP |
INTERNET_FLAG_KEEP_CONNECTION |
INTERNET_FLAG_NO_AUTH |
INTERNET_FLAG_NO_COOKIES |
INTERNET_FLAG_NO_UI |
INTERNET_FLAG_RELOAD |
INTERNET_FLAG_SECURE |
INTERNET_FLAG_IGNORE_CERT_CN_INVALID;
if (0 < ::lstrlen(szExtraInfo))
::lstrcat(szUrlPath, szExtraInfo);
hRequest = ::HttpOpenRequest(hConnect, L"POST", szUrlPath, NULL, NULL, NULL, dwOpenRequestFlags, 0);
if (NULL == hRequest)
break;
::RtlZeroMemory(&internetBuffers, sizeof(internetBuffers));
internetBuffers.dwStructSize = sizeof(internetBuffers);
internetBuffers.dwBufferTotal = dwPostDataSize;
DWORD dwFlags = dwFlags | SECURITY_FLAG_IGNORE_UNKNOWN_CA;
::InternetSetOption(hRequest, INTERNET_OPTION_SECURITY_FLAGS,&dwFlags, sizeof(dwFlags));
bRet = ::HttpSendRequestEx(hRequest, &internetBuffers, NULL, 0, 0);
if (FALSE == bRet)
break;
bRet = ::InternetWriteFile(hRequest, pUploadData, dwUploadDataSize, &dwRet);
if (FALSE == bRet)
break;
bRet = ::HttpEndRequest(hRequest, NULL, 0, 0);
if (FALSE == bRet)
break;
pResponseHeaderIInfo = new unsigned char[dwResponseHeaderIInfoSize];
if (NULL == pResponseHeaderIInfo)
break;
::RtlZeroMemory(pResponseHeaderIInfo, dwResponseHeaderIInfoSize);
bRet = ::HttpQueryInfo(hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, pResponseHeaderIInfo, &dwResponseHeaderIInfoSize, NULL);
if (FALSE == bRet)
break;
printf("[HTTP_Upload_ResponseHeaderIInfo]\n\n%s\n\n", pResponseHeaderIInfo);
bRet = Http_GetContentLength((char*)pResponseHeaderIInfo, &dwResponseBodyDataSize);
if (FALSE == bRet)
break;
pBuf = new BYTE[dwBufSize];
if (NULL == pBuf)
break;
pResponseBodyData = new BYTE[dwResponseBodyDataSize];
if (NULL == pResponseBodyData)
break;
::RtlZeroMemory(pResponseBodyData, dwResponseBodyDataSize);
do {
::RtlZeroMemory(pBuf, dwBufSize);
bRet = ::InternetReadFile(hRequest, pBuf, dwBufSize, &dwRet);
if (FALSE == bRet)
break;
::RtlCopyMemory((pResponseBodyData + dwOffset), pBuf, dwRet);
dwOffset = dwOffset + dwRet;
} while (dwResponseBodyDataSize > dwOffset);
} while (FALSE);
if (NULL != pResponseBodyData) {
delete[]pResponseBodyData;
pResponseBodyData = NULL;
};
if (NULL != pBuf) {
delete[]pBuf;
pBuf = NULL;
};
if (NULL != pResponseHeaderIInfo) {
delete[]pResponseHeaderIInfo;
pResponseHeaderIInfo = NULL;
};
if (NULL != hRequest) {
::InternetCloseHandle(hRequest);
hRequest = NULL;
};
if (NULL != hConnect) {
::InternetCloseHandle(hConnect);
hConnect = NULL;
};
if (NULL != hInternet) {
::InternetCloseHandle(hInternet);
hInternet = NULL;
};
return bRet;
};