1. 程式人生 > >CHttpFile網路互動功能實現...

CHttpFile網路互動功能實現...

程式內部讀取網路資訊, 該程式碼可以通過網路提交驗證密碼再進行判斷... 

首先,需要在檔案頭加上 #include <afxinet.h> 

CInternetSession mySession(NULL,0);
 CHttpFile* myHttpFile=NULL;

 CString myData;
 CString myUrl;
 myUrl = "http://127.0.0.1/yanz.php?name=" + m_myName + "&password=" + m_myPassword;
 myHttpFile=(CHttpFile*)mySession.OpenURL(myUrl);
 while(myHttpFile->ReadString(myData))
 {
             m_SiteInfo = myData;
 }
 
 if( m_SiteInfo == "hao" ){
         CDialog::OnCancel();
 }else{
         AfxMessageBox( "密碼錯誤", NULL, MB_OK );
 }

 myHttpFile->Close();
 mySession.Close();

-----------------------------------------------

CHttpFile Class Members

Construction

Creates a CHttpFile object.

Operations

Adds headers to the request sent to an HTTP server.
Sends a request to an HTTP server.
Sends a request to an HTTP server using the Write or WriteString methods of CInternetFile.
Ends a request sent to an HTTP server with the SendRequestEx member function.
Returns the response or request headers from the HTTP server.
Retrieves the status code associated with an HTTP request and places it in the supplied dwStatusCode parameter.
Gets the verb that was used in a request to an HTTP server.
Gets the target object of the verb in a request to an HTTP server.
Gets the URL for the specified file.
Close Closes the CHttpFile and frees its resources.