forked from JelinYao/HttpInterface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpClient.h
More file actions
49 lines (42 loc) · 1.62 KB
/
Copy pathHttpClient.h
File metadata and controls
49 lines (42 loc) · 1.62 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
#pragma once
#include "../httpHeader.h"
class CWinHttp
: public IWinHttp
{
public:
CWinHttp(void);
virtual ~CWinHttp(void);
virtual void SetTimeOut(int dwConnectTime, int dwSendTime, int dwRecvTime);
virtual string Request(LPCSTR lpUrl, HttpRequest type, LPCSTR lpPostData = NULL, LPCSTR lpHeader=NULL);
virtual string Request(LPCWSTR lpUrl, HttpRequest type, LPCSTR lpPostData = NULL, LPCWSTR lpHeader=NULL);
virtual void FreeInstance() { delete this; }
virtual bool DownloadFile(LPCWSTR lpUrl, LPCWSTR lpFilePath);
virtual bool DownloadToMem(LPCWSTR lpUrl, OUT void** ppBuffer, OUT int* nSize);
virtual void SetDownloadCallback(IHttpCallback* pCallback, void* pParam);
virtual HttpInterfaceError GetErrorCode() { return m_paramsData.errcode; }
virtual void AddHeader(LPCSTR key, LPCSTR value);
virtual int GetResponseCode() { return m_nResponseCode; }
protected:
bool Init();
void Release();
//init
bool InitConnect(LPCWSTR lpUrl, HttpRequest type, LPCSTR lpPostData=NULL, LPCWSTR lpHeader=NULL);
bool ConnectHttpServer(LPCWSTR lpIP, WORD wPort);
bool CreateHttpRequest(LPCWSTR lpPage, HttpRequest type, DWORD dwFlag=0);
bool SendHttpRequest(LPCSTR lpPostData=NULL, LPCWSTR lpHeader=NULL);
//query
bool QueryRawHeaders(OUT wstring& strHeaders);
bool QueryContentLength(OUT DWORD& dwLength);
int QueryStatusCode();
private:
int m_nResponseCode;
bool m_bHttps;
HINTERNET m_hInternet;
HINTERNET m_hConnect;
HINTERNET m_hRequest;
int m_nConnTimeout;
int m_nSendTimeout;
int m_nRecvTimeout;
CHttpHeader m_header;
HttpParamsData m_paramsData;
};