纯C++的Socket访问Http封装类
1.项目中要使用c++++来访问Web服务器,从网上找了个C++的封装类,其中调用了MFC,
在VC2005上用能用,但是移植到VC2003就出问题了,干脆修改成了纯C++的,不敢独享,share之。
2.以下是调用方法:
#include "stdafx.h"
#include <iostream>
#include <string>
#include "http/request.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Request myRequest; //初始化类
string sHeaderSend; //定义http头
string sHeaderReceive; //返回头
string sMessage=""; //返回页面内容
bool IsPost=false; //是否Post提交
int i =myRequest.SendRequest(IsPost, "doc.guandang.net;, sHeaderSend,
sHeaderReceive, sMessage);
if (i)
{
cout<<"Http头:"<<endl;
cout<< sHeaderSend <<endl;
cout<<"响应头"<<endl;
cout<< sHeaderReceive <<endl;
cout<<"网页内容"<<endl;
cout<< sMessage <<endl;
}else
{
cout<<"网络不可到达"<<endl;
}
system("pause");
return 0;
}
#include "stdafx.h"
#include <iostream>
#include <string>
#include "http/request.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Request myRequest; //初始化类
string sHeaderSend; //定义http头
string sHeaderReceive; //返回头
string sMessage=""; //返回页面内容
bool IsPost=false; //是否Post提交
int i =myRequest.SendRequest(IsPost, "doc.guandang.net;, sHeaderSend,
sHeaderReceive, sMessage);
if (i)
{
cout<<"Http头:"<<endl;
cout<< sHeaderSend <<endl;
cout<<"响应头"<<endl;
cout<< sHeaderReceive <<endl;
cout<<"网页内容"<<endl;
cout<< sMessage <<endl;
}else
{
cout<<"网络不可到达"<<endl;
}
system("pause");
return 0;
}
类代码如下
//******************************************
//纯C++的socket访问Http封装类,Neeao修改
//doc.guandang.net
//2009-08-25
//******************************************
#if !defined(AFX_REQUEST_H__9F2C9BB6_CBA7_40AF_80A4_09A1CE1CE220__INCLUDED_)
#define AFX_REQUEST_H__9F2C9BB6_CBA7_40AF_80A4_09A1CE1CE220__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winsock2.h>
#pragma comment(lib, "WS2_32")
using namespace std;
#define MEM_BUFFER_SIZE 10
/*
HTTPRequest: Structure that returns the HTTP headers and message
from the request
*/
typedef struct
{
L
CSocketFile 对象连接到 CArchive 对象上,然后可以将数据串行化,以使用 MFC 系列来简化发送和接收数据,而 最终实现利用网络的 Socket 传输和本机上的流传输一样...
{建立服务器} import java.net.*; import java.io.*; public class server { private serversocket ss; private socket socket; private bufferedreader in; ...
C++类及其对象的封装性_化学_自然科学_专业资料。实验一 C++类及其对象的封装性 一、实验目的和要求(1) (2) (3) (4) (5) 了解 C++类的构成。 掌握声...
Socket5&HTTP代理源码(封装类)_IT/计算机_专业资料。我亲自写的HTTP、SOCKET5通信代理,封装成了类,可以下载来直接用 !/***文件说明*** ** 文件名: Proxy....
==SOCKET_ERROR) { closesocket(s); WSACleanup(); file:///C/Documents ...id=68 4 http://www.vckbase.com/document/viewdoc/?id=71 2 11.多线程...
C++ Socket连接实现_信息与通信_工程科技_专业资料 暂无评价0人阅读0次下载举报文档 C++ Socket连接实现_信息与通信_工程科技_专业资料。http://lc52520.itey...
C++程序-类的封装_工学_高等教育_教育专区。c++实验 源程序 简单实验代码实验1 类的封装专业班级 学号 姓名 一、实验目的 1. 2. 3. 4. 熟悉类定义的一般...
Socket 模型详解 转] 模型详解[转 Winsock 的 I/O 操作: 1、 两种 I/O ...sin_port 为服务端口,注意不要使用 已固定的服务端口,如 HTTP 的端口 80 等...
c++socket。vc下socket使用说明C/S结构(client/server结构) 客户端/服务器结构...(m_SerPORT);这个括号内的是服务器的端口号 这个都是系统封装的函数 必须的...
=INVALID_SOCKET) Close(); } void MySock::OnReceive(int nErrorCode) { m_nLength=Receive(m_szBuffer,sizeof(m_szBuffer),0); //下面两行代码用来获取...
热门文档