⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 request.h

📁 初学者学习HTTP协议的有用代码
💻 H
字号:
// Request.h: interface for the Request class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_REQUEST_H__F90A9FAB_6BC7_4190_97A1_30E113A4AFCD__INCLUDED_)
#define AFX_REQUEST_H__F90A9FAB_6BC7_4190_97A1_30E113A4AFCD__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winsock2.h>
#include "HttpLookDlg.h"	// Added by ClassView
#pragma comment(lib,"wsock32")
#define MEM_BUFFER_SIZE 10

/* 
	HTTPRequest: Structure that returns the HTTP headers and message
					from the request
*/
typedef struct
{ 
    LPSTR headerSend;								// Pointer to HTTP header Send 
	LPSTR headerReceive;							// Pointer to HTTP headers Receive
    LPSTR message;									// Pointer to the HTTP message 
    long messageLength;								// Length of the message 
} HTTPRequest;

/* 
	MemBuffer:	Structure used to implement a memory buffer, which is a
				buffer of memory that will grow to hold variable sized
				parts of the HTTP message. 
*/
typedef struct
{
    unsigned	char *buffer;
    unsigned	char *position;
    size_t		size;
} MemBuffer;

class Request  
{
public:
	Request();
	virtual ~Request();
private:
	void MenBufferCreate(MemBuffer &m);
	void MenBufferGrow(MemBuffer &m);
	void MenBufferAddbyte(MemBuffer &m,BYTE byte);
	void MenBufferAdd(MemBuffer &m,unsigned char * buffer,size_t size);
//	BOOL ValidURL(CString &strURL);
	int SendHttp(LPCSTR url,HWND hwnd,LPCSTR headerReceive,BYTE *post,
        DWORD postLength,HTTPRequest *req);
	DWORD GetHostAddress(LPCSTR host);
	void SendString(SOCKET sock,LPCSTR str);
	void ParseURL(LPCSTR url,CString &protocol,CString &host,CString &request,int &port);
public:
	void SendRequest(LPCSTR url,HWND hwnd,int nIsPost,CString &strHeaderPost,CString &strHeaderSend,
						  CString &strHeaderRecive,CString &strMessage);
protected:
	CHttpLookDlg httpLook;
};

#endif // !defined(AFX_REQUEST_H__F90A9FAB_6BC7_4190_97A1_30E113A4AFCD__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -