自己写的3

AskaRo2010 2010-11-22 06:31:00

#ifndef _CWEB_H_
#define _CWEB_H_

#include <string>
#include <list>

using namespace std;

#define WEB_DEFAULT_HTTP_PORT 80
#define WEB_DEFAULT_PROXY_PORT 8080

#define WEB_ERR_NULL 0x0000
#define WEB_ERR_CREATE_SOCK 0x0001
#define WEB_ERR_GET_IP 0x0002
#define WEB_ERR_CONNECT 0x0004


#define READ_UNCOMPRESS_ERR 0x0000
#define READ_TEXT_HTML 0x0001
#define READ_TEXT_CSS 0x0002
#define READ_IMAGE_JPEG 0x0004
#define READ_IMAGE_PNG 0x0008
#define READ_IMAGE_GIF 0x0010
#define READ_IMAGE_X_ICON 0x0020
#define READ_APPLICATION_JAVASCRIPT 0x0040
#define READ_APPLICATION_X_JAVASCRIPT 0x0080
#define READ_OTHERS 0x0100


#define CONTENT_TYPE_TEXT_HTML "text/html"
#define CONTENT_TYPE_TEXT_CSS "text/css"
#define CONTENT_TYPE_IMAGE_JPEG "image/jpeg"
#define CONTENT_TYPE_IMAGE_PNG "image/png"
#define CONTENT_TYPE_IMAGE_GIF "image/gif"
#define CONTENT_TYPE_IMAGE_X_ICON "image/x-icon"
#define CONTENT_TYPE_APPLICATION_JAVASCRIPT "application/javascript"
#define CONTENT_TYPE_APPLICATION_X_JAVASCRIPT "application/x-javascript"


#define MSG_ITEM_DATE "Date: "
#define MSG_ITEM_SERVER "Server: "
#define MSG_ITEM_CONTENT_TYPE "Content-Type: "
#define MSG_ITEM_CONTENT_ENCODING "Content-Encoding: "
#define MSG_ITEM_CONTENT_LENGTH "Content-Length: "
#define MSG_ITEM_TRANSFER_ENCODING "Transfer-Encoding: "
#define MSG_ITEM_CONNECTION "Connection: "
#define MSG_ITEM_CACHE_CONTROL "Cache-Control: "
#define MSG_ITEM_LAST_MODIFIED "Last-Modified: "
#define MSG_ITEM_EXPIRES "Expires: "
#define MSG_ITEM_PRAGMA "Pragma: "
#define MSG_ITEM_DPOOL_HEADER "DPOOL_HEADER: "
#define MSG_ITEM_VARY "Vary: "
#define MSG_ITEM_ACCEPT_RANGES "Accept-Ranges: "


class CCookie
{
public:
CCookie(const char* pStrCookie);
CCookie(const char* pStrKey, const char* pStrValue);
CCookie(const CCookie& cookie);
virtual ~CCookie();
public:
const char* GetKey();
const char* GetValue();
void SetValue(const char* pStrValue);
private:
CCookie();

private:
string m_strKey;
string m_strValue;
};

class CWeb
{
public:
CWeb();
virtual ~CWeb();
public:
void SetAgent(const char* pStrUserAgent);

static void SetProxy(const char* pStrProxyName, unsigned short usProxyPort = WEB_DEFAULT_PROXY_PORT);
int SetServer(const char* pStrServerName, unsigned short usServerPort = WEB_DEFAULT_HTTP_PORT);

void SetRequest
(
const char* pStrVerb,
const char* pStrObjName,
const char* pStrAccept,
const char* pStrReferer,
const char* pStrAcceptEncoding,
const char* pStrHeaders
);

const char* GetRequest();

int SendRequest();

int ReadData();

const char* GetMsg();

bool GetMsgItem(string& strItem,const char* pStrMsgItemKey);

const char* GetData();

unsigned long GetDataSize();

const char* GetHtml();

private:
CWeb(CWeb& obj);

const char* ReadMsg();
bool IsGzip();
bool CheckItem(const char* pStrMsgItemKey, const char* pStrMsgItemValue);
void ReadDataByLen(char* pBuf,unsigned long ulCurBufDataLen, unsigned long ulDestLen);
void SetCookie();
bool IsProxy();
int GetContentType();
private:
static unsigned int ms_uiWSAStartupCount;
static string ms_strProxy;
static unsigned short ms_usProxyPort;
string m_strHost;
unsigned short m_usHostPort;

string m_strUserAgent;

int m_sock;
void* m_pAddress;

string m_strRequest;

string m_strMsg;
char* m_pData;
unsigned long m_ulDataSize;

bool m_DataAndHtmlIsSynchronous;
string m_strHtml;

list<CCookie> m_cookieList;
};

#endif//_CWEB_H_
...全文
55 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ayw215 2010-11-22
  • 打赏
  • 举报
回复
http协议?
实现呢

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧