MFC網路編程1

來源:互聯網
上載者:User

      在vc中,可以採用兩種形式的網路編程方式,一種是使用MFC的網路編程方式,一種是直接使用類WinInet API的編程方式。

      WinInet類是對WinInet API的封裝,它有許多優越之處,程式員無需瞭解網路傳輸協議和windows通訊端的細節,只需簡單的調用裡的幾個成員函數就可與伺服器建立串連。它提供的幾個管理資料在網路中傳輸的成員函數使用應用程式擷取伺服器的過程,就像從硬碟中讀取資料一樣簡單。

      WinInet 類的編程模型:1 建立CInternetSession類對象,初始化Internet 會話;2 建立CInternetSession對象與伺服器的串連,調用函數CInternetSession::GetHttpConnection(),CInternetSession::GetFtpConnection()函數開啟對應協議的串連,只裡面需要制定伺服器類型,連接埠號碼,使用者名稱,密碼,得到相應伺服器對象 3 在串連時,可以調用CInternetSession::QueryOption函數  進行資訊的查詢。4 客戶應用程式在進行操作時,需要調用回呼函數監視會話的狀態。5 以上是獲得伺服器的環境狀態,通常客戶應用程式的主要功能是處理資料,應擷取CIneternet的執行個體:CFtpConnection::openFile()得到CFtpFile的對象指標。另外一種方法是CInternetSession::OpenURL()得到檔案對象,得到伺服器對象後就可以對伺服器對象進行讀取了,此後通過檔案檢索,基本上跟操作本地檔案資料是一樣的。

    WinInet API進行網路編程需要大量的底層編程工作,包括win32編程,FTP,HTTP協議本身的瞭解,該函數包括WinInet API函數,自動撥號函數,URL函數,ftp函數,http函數,cookie函數,身分識別驗證函數以及緩衝函數。其函數列表有:

Wininet api函數列表

Platform SDK: Windows Internet

 

CommitUrlCacheEntry
CreateMD5SSOHash
CreateUrlCacheEntry
CreateUrlCacheGroup
DeleteUrlCacheEntry
DeleteUrlCacheGroup
DetectAutoProxyUrl
FindCloseUrlCache
FindFirstUrlCacheEntry
FindFirstUrlCacheEntryEx
FindFirstUrlCacheGroup
FindNextUrlCacheEntry
FindNextUrlCacheEntryEx
FindNextUrlCacheGroup
FtpCommand
FtpCreateDirectory
FtpDeleteFile
FtpFindFirstFile
FtpGetCurrentDirectory
FtpGetFile
FtpGetFileSize
FtpOpenFile
FtpPutFile
FtpRemoveDirectory
FtpRenameFile
FtpSetCurrentDirectory
GetUrlCacheEntryInfo
GetUrlCacheEntryInfoEx
GetUrlCacheGroupAttribute
GopherAttributEnumerator
GopherCreateLocator
GopherFindFirstFile
GopherGetAttribute
GopherGetLocatorType
GopherOpenFile
HttpAddRequestHeaders
HttpEndRequest
HttpOpenRequest
HttpQueryInfo
HttpSendRequest
HttpSendRequestEx
InternetAttemptConnect
InternetAutodial
InternetAutodialHangup
InternetCanonicalizeUrl
InternetCheckConnection
InternetCloseHandle
InternetCombineUrl
InternetConfirmZoneCrossing
InternetConnect
InternetCrackUrl
InternetCreateUrl
InternetDeInitializeAutoProxyDll
InternetDial
InternetErrorDlg
InternetFindNextFile
InternetGetConnectedState
InternetGetConnectedStateEx
InternetGetCookie
InternetGetCookieEx
InternetGetLastResponseInfo
InternetGetProxyInfo
InternetGoOnline
InternetHangUp
InternetInitializeAutoProxyDll
InternetLockRequestFile
InternetOpen
InternetOpenUrl
InternetQueryDataAvailable
InternetQueryOption
InternetReadFile
InternetReadFileEx
InternetSetCookie
InternetSetCookieEx
InternetSetDialState
InternetSetFilePointer
InternetSetOption

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.