目前visual c++ 6.0支持的网络编程有三种方式:一种是isapi,既基于网络
服务器应用程序设计接口的程序,主要用来创建ftp服务器、proxy代理服务器、http
服务器、smtp服务器、bbs服务器、网络数据库服务器等服务器程序。一种是windows
socket2,即基于windows套接口编程,源于unix的套接口编程。还有一种便是wininet
基于国际互连网客户端应用设计接口的程序。
mfc把这些国际互连网方面的扩展内容封装到一系列标准的易于使用的类中。用户
可以直接调用win32的函数或使用mfc的wininet类库,来写一个客户端应用。用户可以通
过wininet来做以下应用:
1 下载html主页。
2 发送ftp请求,上载、下载文件或得到目录列表。
3 使用gopher的菜单系统来访问互连网上的资源。
mfc提供了以下编写互连网客户端应用的类库和全局函数:
1 cinternetsession
用它来创建或初始化单一的或多个同时进行的对话。
2 cinternetconnection
它使用户连接到互连网服务器上,它是cftpconnection、chttpconnection和
cgopherconnection的基类。
3 cinternetfile
它和派生类chttpfile和cgopherfile允许通过互连网协议访问远程系统上文件
4 cfilefind
它执行本地文件的查找。
举例:
cfilefind finder;
bool bworking=finder.findfile("*.*");
while(bworking)
{
bworking=finder.findnextfile();
cout<<(lpctstr)finder.getfinename()<<endl;
}
5 cinternetexception
包含了两个公共数据成员:一个保存和异常相关的错误代码,一个保存和异常相关
的应用程序的上下文标志符。
6 afxparselurl(lpctstr pstrurl,dword& dwservicetype,cstring& strserver,
cstring& strobject,internet_port& nport);
如果url解析成功返回非零值。
7 afxgetinternethandletype(hinternet hquery);
返回所有互连网服务类型在文件wininet.h中定义。