WinInet开发Internet应用程序new

上传人:xins****2008 文档编号:111122131 上传时间:2019-11-01 格式:DOCX 页数:6 大小:158.96KB
返回 下载 相关 举报
WinInet开发Internet应用程序new_第1页
第1页 / 共6页
WinInet开发Internet应用程序new_第2页
第2页 / 共6页
WinInet开发Internet应用程序new_第3页
第3页 / 共6页
WinInet开发Internet应用程序new_第4页
第4页 / 共6页
WinInet开发Internet应用程序new_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《WinInet开发Internet应用程序new》由会员分享,可在线阅读,更多相关《WinInet开发Internet应用程序new(6页珍藏版)》请在金锄头文库上搜索。

1、开发Internet应用程序Internet应用程序开发的几种类型:1、使用WinInet类开发Internet应用程序:WinInet类支持HTTP、FTP和Gopher等标准的协议。2、使用Windows Socket开发Internet应用程序:Winsock标准定义了一个DLL接口来连接Internet,MFC使用CAsyncSocket和CSocket类对接口进行了封装。3、使用消息收发API(MAPI:Message API) 开发Internet应用程序:使用MAPI可以很方便的向其他应用程序发送电子邮件、语音邮件或传真等功能。WinInet类是一个总称,目前的版本中分为四组CI

2、nternetSession类CInternetConnection类(连接类)CFileFind类(Internet文件查找类)CInternetFile类和CGopherLocator类 (1)CInternetSession类直接继承自CObject类,该类用来建立与某个Internet服务器的会话。还可以向代理服务器描述连接,如果应用程序所使用的Internet连接必须保持一段时间,则可以在CWinApp类中创建相应的CInternetSession成员。(2)CInternetConnection类及其派生类CHttpConnection、CFtpConnection和CGopher

3、Connection类,这些类帮助用户管理与Internet服务器的连接,同时还提供一些函数完成和响应服务器的通信:CInternetConnection:用于管理与Internet服务器的连接;CFtpConnection:用于管理与FTP服务器的连接,可以对服务器上的文件和目录进行直接操作;CGopherConnection:管理与Gopher服务器的连接;CHttpConnection:管理与HTTP服务器的连接。(3)CInternetFile类及其派生类CHttpFile、CGopherFile。这些类实现对远程系统上的文件的存取工作。文件类还包含CFileFind类及其派生类CFt

4、pFileFind、CGopherFileFind类。CFileFind类直接继承于CObject类,这些类实现对本地和远程系统上的文件的搜索和定位工作。CInternetFile:允许对使用Internet协议的远程系统中的文件进行操作CGopherFile:为在Gopher服务器上进行文件检索和读取操作提供支持CHttpFile:提供对HTTP服务器上的文件进行操作的支持CFindFile:文文件检索提供支持CFtpFileFind:为在FTP服务器上进行的文件检索操作提供支持CGopherFileFind:为在Gopher服务器上进行的文件检索操作提供支持(4)在从Gopher服务器中获

5、取信息之前,必须先获得该服务器的定位器,而CGopherLocator类的主要功能就是从Gopher服务器中得到定位并确定定位器的类型。WinInet类编程实例 在新加入的类中增加如下三个public的成员函数,在头文件MyWinInetClass.h中可看到这些函数。CString ConnectFtp(const CString sUrl);/完成连接Ftp功能的函数CString ConnectHttp(const CString sUrl)/完成连接Http功能的函数CString ConnectGopher(const CString sUrl);为了建立Internet的会话,新增

6、加的CmyWinInetClass类中加入一个private型成员变量m_session:CInternetSession m_session;/建立Internet会话由于在上面定义了一个CWinInet类的对象,所以还需要在MyWinInetClass.h头文件中加入如下代码:#include afxinet.h#include #pragma comment(lib, wininet.lib)为CMyWinInetClass类添加三个用于连接的成员函数,它们分别是ConnectFtp、ConnectHttp和ConnectGopher。CString CMyWinInetClass:Co

7、nnectFtp(const CString sUrl)CString sResult;/存储连接信息的字符串CFtpConnection *Ftpconnection = NULL;sResult = sResult + Trying to connect Ftp sites + sUrl + rn;Ftpconnection = m_session.GetFtpConnection(sUrl);/建立到Ftp服务器的连接if(Ftpconnection)sResult = sResult + Connection established.rn;CString sCurDir;Ftpconn

8、ection-GetCurrentDirectory(sCurDir);/得到Ftp服务器的当前目录sResult = sResult + current directory is + sCurDir + rn;Ftpconnection-Close();/关闭连接else sResult=sResult+There are some errors in finding this Ftp sites;return sResult; CString CMyWinInetClass:ConnectHttp(const CString sUrl)CString sResult;CInternetFi

9、le *hHttpFile = NULL;sResult = sResult + Trying to connect Http sites + sUrl + rn;hHttpFile = (CInternetFile *)m_session.OpenURL(sUrl);/得到文件指针if(hHttpFile)sResult = sResult + Connection established.rn;CString sLine;while(hHttpFile-ReadString(sLine)/读取Http服务器上的内容sResult = sResult + sLine + rn;hHttpFi

10、le-Close(); /关闭连接elsesResult = sResult + There are some errors in finding this Http sites;return sResult; CString CMyWinInetClass:ConnectGopher(const CString sUrl)CString sResult;CInternetFile *hGopherFile=NULL;sResult = sResult + Trying to connect Gopher sites + sUrl + rn;hGopherFile = (CInternetFi

11、le *)m_session.OpenURL(sUrl);/得到文件指针if(hGopherFile)sResult = sResult + Connection established.rn;CString sLine;while(hGopherFile-ReadString(sLine)/读取Gopher服务器内容sResult = sResult+sLine+rn;hGopherFile-Close();/结束连接elsesResult = sResult + There are some errors in finding this Gopher sites;return sResul

12、t;在CMyInternetDlg类中增加一个public成员变量CMyWinInetClass m_WinInetClass;变量m_WinInetClass是CMyWinInetClass类的一个对象,所以还要在WinInetDlg.h头文件加入自定义类的头文件:#include MyWinInetClass.h三个消息处理函数增加代码如下:void CWinInetDlg:OnButtonFtp() UpdateData(TRUE);/从对话框读入地址信息m_Urlm_EditResult=;/调用自定义类的成员函数,连接Ftp服务器,m_Url为地址m_EditResult = m_E

13、ditResult + m_WinInetClass.ConnectFtp(m_Url); UpdateData(FALSE);void CWinInetDlg:OnButtonHttp() UpdateData(TRUE);/从对话框读入地址信息m_Urlm_EditResult=;/调用自定义类的成员函数,连接Http服务器,m_Url为地址m_EditResult = m_EditResult + m_WinInetClass.ConnectHttp(m_Url);UpdateData(FALSE);void CWinInetDlg:OnButtonGopher() UpdateData(TRUE);/从对话框读入地址信息m_Urlm_EditResult=;/调用自定义类的成员函数,连接Gopher服务器,m_Url为地址m_EditResult = m_EditResult + m_WinInetClass.ConnectGopher(m_Url);UpdateData(FALSE);总结:只是实现了读取服务器的内容,相当于网页的代码。FTP怎样实现呢?以及Gopher是什么

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号