-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTUrlGet.h
76 lines (65 loc) · 1.4 KB
/
TUrlGet.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
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <WinSock2.h>
//#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;
class TUrlGet
{
private:
string _ip;
string _recvData;
char _buff[2048];
bool _err;
SOCKET _s;
void parseUrl(const string& url);
bool sendGet();
bool selectSend(int timeout);
bool selectRecv(int timeout);
bool conn();
void postRecv();
void clearRes();
string queryDNS(const string & url);
static string UTF8ToGBK(const std::string& strUTF8)
{
int len = MultiByteToWideChar(CP_UTF8, 0, strUTF8.c_str(), -1, NULL, 0);
unsigned short * wszGBK = new unsigned short[len + 1];
memset(wszGBK, 0, len * 2 + 2);
MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)strUTF8.c_str(), -1, (LPWSTR)wszGBK, len);
len = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)wszGBK, -1, NULL, 0, NULL, NULL);
char *szGBK = new char[len + 1];
memset(szGBK, 0, len + 1);
WideCharToMultiByte(CP_ACP,0, (LPWSTR)wszGBK, -1, szGBK, len, NULL, NULL);
//strUTF8 = szGBK;
std::string strTemp(szGBK);
delete[]szGBK;
delete[]wszGBK;
return strTemp;
}
public:
string getRecvData(const string& url,int intval)
{
string ret = "";
parseUrl(url);
conn();
if(selectSend(intval) == true)
{
if(selectRecv(intval) == true)
{
return UTF8ToGBK(_recvData);
}
else
{
return ret;
}
}
else
{
return ret;
}
}
TUrlGet(void);
public:
~TUrlGet(void);
};