-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpClientGet.cpp
More file actions
78 lines (66 loc) · 2.06 KB
/
Copy pathHttpClientGet.cpp
File metadata and controls
78 lines (66 loc) · 2.06 KB
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
#include "HttpClientGet.h"
CHttpClientGet::CHttpClientGet(void)
{
m_lpData = NULL;
m_dwDataSize = 0;
m_dwWriteIndex = 0;
}
CHttpClientGet::~CHttpClientGet(void)
{
}
DWORD CHttpClientGet::GetDataSize()
{
return m_dwDataSize;
}
BOOL CHttpClientGet::GetData( LPVOID lpBuffer, DWORD dwBufferSize, DWORD& dwWrite )
{
BOOL bContinue = TRUE;
dwWrite = 0;
if ( m_dwDataSize > m_dwWriteIndex + dwBufferSize ) {
dwWrite = dwBufferSize;
}
else {
dwWrite = m_dwDataSize - m_dwWriteIndex;
bContinue = FALSE;
}
if ( 0 != memcpy_s(lpBuffer, dwBufferSize, (LPBYTE)m_lpData + m_dwWriteIndex, dwWrite) ){
bContinue = FALSE;
}
return bContinue;
}
BOOL CHttpClientGet::TransDataToServer( const std::wstring& wstrUrl, DWORD dwTimeout,
VecStParam& vecParam, LPVOID lpData, DWORD dwDataLenInBytes )
{
m_lpData = lpData;
m_dwDataSize = dwDataLenInBytes;
m_vecParam.assign(vecParam.begin(), vecParam.end());
m_dwWriteIndex = 0;
return TransmiteData(wstrUrl, eGet, dwTimeout);
}
std::wstring CHttpClientGet::GenerateExtInfo( const VecStParam& VecExtInfo )
{
std::wstring wstrExtInf;
for ( VecStParamCIter it = VecExtInfo.begin(); it != VecExtInfo.end(); it++ ) {
if ( false == wstrExtInf.empty() ) {
wstrExtInf += L"&";
}
wstrExtInf += it->wstrKey;
wstrExtInf += L"=";
wstrExtInf += it->wstrValue;
}
return wstrExtInf;
}
BOOL CHttpClientGet::ModifyRequestHeader( HINTERNET hRequest )
{
std::wstring wstrHeader[] = { L"Content-type: application/x-www-form-urlencoded\r\n"};
for ( size_t i = 0; i < ARRAYSIZE(wstrHeader); i++ ) {
WinHttpAddRequestHeaders(hRequest, wstrHeader[i].c_str(), wstrHeader[i].length(), WINHTTP_ADDREQ_FLAG_ADD);
}
return TRUE;
}
VOID CHttpClientGet::AddExtInfo( VecStParam& VecExtInfo )
{
for ( VecStParamCIter it = m_vecParam.begin(); it != m_vecParam.end(); it++ ) {
VecExtInfo.push_back(*it);
}
}