📄 clienthttp.h
字号:
/*******************************************************************************
* (C) Copyright 2008 Giant Electronics LTD
*
* These computer program listings and specifications are the property of Giant
* Electronics LTD and shall not be reproduced or copied or used in whole or in
* part without written permission from Giant Electronics LTD .
*
* Project: IViewer
* File Name: ClientHTTP.h
* Programer(s): Ben Zhan
* Created: 20080729
* Description: interface of encapsulating HTTP protocol
* This class encapsulates HTTP protocol and provides the functionality to request
and read files on an HTTP server.
*******************************************************************************/
#if !defined(AFX_CLIENTHTTP_H__BDF77B47_0251_4613_BE79_7DADC95775B4__INCLUDED_)
#define AFX_CLIENTHTTP_H__BDF77B47_0251_4613_BE79_7DADC95775B4__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ClientSocket.h"
#define E_HTTP_CONNECT_FAILED 0x15
#define E_HTTP_REQUEST_FAILED 0x16
#define E_HTTP_RECEIVEHEADER_FAILED 0x17
#define E_HTTP_RECEIVEBODY_FAILED 0x18
#define E_HTTP_SUCCEED 0x19
#define E_HTTP_OTHERERROR 0x20
#define HTTPHEADER_MAX_SIZE 2048
class CClientHTTP : public CClientSocket
{
public:
CClientHTTP();
virtual ~CClientHTTP();
// Send request by GET method
int SendGETRequest(LPCSTR lpszURL,HANDLE hCancelEvent = NULL);
// Send request by POST method
int SendPOSTRequest(LPCSTR lpszURL, LPBYTE lpPost, DWORD dwPostLength, HANDLE hCancelEvent = NULL);
// Receive HTTP header data
int ReceiveResponseHeader(HANDLE hCancelEvent=NULL);
// Get HTTP status code, 400-500 means error
int GetResponseStatus(DWORD &dwStatusCode);
int GetField(LPCSTR lpszSession, LPSTR lpszValue,LPSTR lpszHeader=NULL); //返回某个域值,-1表示不成功
BYTE* GetResponseHeader(); //取得返回的信息头
private:
BOOL ValidHostChar(TCHAR ch) ;
void ParseURL(LPCSTR lpszURL,LPSTR lpszProtocol,int lprotocol,LPSTR lpHost,int iHost,LPSTR lpRequest,int iRequest,int * piPort);
int SendHTTP(LPCSTR lpszURL,LPCSTR lpszHeaderReceive,BYTE * post,DWORD dwPostLength,HANDLE hCancelEvent);
LPCSTR FormatGETHeader(LPSTR lpszServer,LPSTR lpszObject,long &lLength,
LPSTR lpszCookie=NULL,LPSTR lpszReferer=NULL,
long lFrom=0,long lTo=0,
int nServerType=0); //格式化请求头
LPCSTR FormatGETHeader_HTTPPROXY(LPSTR lpszServer,LPSTR lpszObject,long &lLength,
LPSTR lpszCookie=NULL,LPSTR lpszReferer=NULL,
long lFrom=0,long lTo=0,
int nServerType=0); //格式化请求头
// modified by Ben 2009-05-14
LPCSTR FormatPOSTHeader(LPSTR lpszServer, LPSTR lpszObject, long lPostDataLength, long &lLength);
LPCSTR FormatPOSTHeader_HTTPPROXY(LPSTR lpszServer, LPSTR lpszObject, long lPostDataLength, long &lLength);
public:
DWORD GetMSizeFromW(LPWSTR lpwszStr);
DWORD GetWSizeFromM(LPCSTR lpcszStr);
BOOL MByteToWChar(LPCSTR lpcszStr, LPWSTR lpwszStr, DWORD dwSize);
BOOL WCharToMByte(LPCWSTR lpcwszStr, LPSTR lpszStr, DWORD dwSize);
private:
CHAR m_ResponeHeaderBuf[HTTPHEADER_MAX_SIZE];
CHAR m_RequestHeaderBuf[HTTPHEADER_MAX_SIZE];
};
#endif // !defined(AFX_CLIENTHTTP_H__BDF77B47_0251_4613_BE79_7DADC95775B4__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -