amhttpsocket.h

来自「一个支持EMPP协议的企信通程序,很完整可以马上用,完全socket底层协议编写」· C头文件 代码 · 共 35 行

H
35
字号
//link with wininet.lib

#pragma once

#include <tchar.h>
#include <windows.h>
#include <wininet.h>

/*
	custom errorcodes:
	-1: bad url...
*/

class CAmHttpSocket
{
public:
	void FreeBuffer();
	int GetPageStatusCode(); //get the HTTP statuscode for the last received page
	TCHAR* GetHeaders(const TCHAR *url); //return a pointer th the headers from an url
	int CrackURL(const char* Address,char *scheme,
		char *host ,char *path,
		char *extrainfo,int &port);
	BOOL  PutFile(const char *szFileName,const char *strSource);
	CAmHttpSocket();
	~CAmHttpSocket();
	char* GetPage(const TCHAR *url, DWORD& size,bool Post = false, const char *PostData = NULL, int PostDataLength = -1); //get a page, if post is false, HTTP GET is used othervise HTTP POST is used. if PostDataLength is -1 the data must be NULL terminated...
protected:
	bool PostUrl(const TCHAR *url, const char *PostData, int PostDataLength = -1); //open a page using http post
	TCHAR* GetHeaderLine(TCHAR *s); //get a specific line from the headers
	bool OpenUrl(const TCHAR *url); //open a page using http get
	HINTERNET hIO, hIS, hCO;
	char *ReceivedData; //the internal databuffer
	TCHAR *Headers; //the internal headerbuffer
	int LastError; //internal statuscode...
};

⌨️ 快捷键说明

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