利用Win32的网络函数创建一个网络浏览器

                                     "/MSDN/MSDNINFO/",
                                     HTTP_VERSION,
                                     NULL,
                                     0,
                                     INTERNET_FLAG_DONT_CACHE,
                                     0) ;

// Send the request.
BOOL bSendRequest = ::HttpSendRequest(hHttpFile, NULL, 0, 0, 0);

// Get the length of the file.            
char bufQuery[32] ;
DWORD dwLengthBufQuery = sizeof(bufQuery);
BOOL bQuery = ::HttpQueryInfo(hHttpFile,
                              HTTP_QUERY_CONTENT_LENGTH,
                              bufQuery,
                              &dwLengthBufQuery) ;

// Convert length from ASCII string to a DWORD.
DWORD dwFileSize = (DWORD)atol(bufQuery) ;

// Allocate a buffer for the file.   
char* buffer = new char[dwFileSize+1] ;

// Read the file into the buffer.
DWORD dwBytesRead ;
BOOL bRead = ::InternetReadFile(hHttpFile,
                                buffer,
                                dwFileSize+1,
                                &dwBytesRead);
// Put a zero on the end of the buffer.
buffer[dwBytesRead] = 0 ;

// Close all of the Internet handles.
::InternetCloseHandle(hHttpFile);
::InternetCloseHandle(hConnect) ;
::InternetCloseHandle(hSession) ;

// Display the file in an edit control.
pEditCtrl-&gtSetWindowText(buffer) ;

InternetConnect
    InternetConnet函数连接到一个HTTP,FTP或Gopher服务器:
HINTERNET hConnect = ::InternetConnect(
          hSession,                     //1 HINTERNET hInternetSession
          "www.microsoft.com",          //2 LPCTSTR lpszServerName
          INTERNET_INVALID_PORT_NUMBER, //3 INTERNET_PORT nServerPort
          "",                           //4 LPCTSTR lpszUsername
          "",                           //5 LPCTSTR lpszPassword
          INTERNET_SERVICE_HTTP,        //6 DWORD dwService
          0,                            //7 DWORD dwFlags
          O                             //8 DWORD dwContext
) ;
    第六个参数dwService决定服务类型(HTTP,FTP或Gopher)。在上面的例子中,InternetConnect连接到一个HTTP服务器上,因为dwService被设置成INTERNET_SERVICE_HTTP。第二个参数(设置成www.microsoft.com)提供了服务器的地址。注意,HTTP地址必须为服务器名作语法分析,InternetOpenUrl为我们作语法分析。第一个参数hInternetSession是从InternetOpen返回的句柄。第四个、第五个参数提供一个用户姓名和密码 。这七个参数没有控制任何标志影响HTTP操作。最后一个参数为状态回调函数提供前后关系的信息。

HttpOpenRequest
    一旦和服务器的连接已经建立,我们打开了想要的文件。HttpOpenRequest和HttpSenRequest一起工作打开文件。HttpOpenRequest去创建一个请求句柄并且把参数存储在句柄中。HttpOpenRequest把请求参数送到HTTP服务器。
HINTERNET hHttpFile = ::HttpOpenRequest(
          hConnect,              // 1 HINTERNET hHttpSession
共6页 首页 上一页 [2] [3] [4] [5] [6下一页 尾页>
上一篇:
下一篇: 大型WAV文件的播放
相关信息
相关评论
字母检索 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z