Windows MFC HTTP function process

Windows MFC HTTP function process

1  // establish a connection 
2 = pInternetSession new new the CInternetSession (AfxGetAppName ());
 . 3  
. 4  
. 5  
. 6  // The HttpUr resolved 
. 7  CString the strServer;
 . 8  CString strObject;
 . 9  DWORD dwServiceType;
 10  INTERNET_PORT nPort;
 . 11  AfxParseURL (m_strHttpUrl, dwServiceType, the strServer, strObject, nPort);
 12 is  
13 is  
14  
15  // create objects CHttpConnection 
16 pHttpConnection = pInternetSession-> GetHttpConnection (the strServer, nPort);
 . 17  
18 is  
. 19  
20 is  //Opening an HTTP request 
21 is strTempObject = strObject + " ccvid =% S & the format =% S & Time =% I64u? " 
22 is pHttpFile = pHttpConnection-> OpenRequest (the CHttpConnection :: HTTP_VERB_POST / * HTTP_VERB_GET * / , strTempObject / * strObject * / );
 23 is  
24  
25  
26 is  // Add request sent to the HTTP server head 
27  " the Content-the Type: file application / X-WWW-form-urlencoded; charset = UTF-. 8 " 
28 pHttpFile-> AddRequestHeaders (XXX);
 29  
30  
31 is  
32  // to HTTP server sends a request 
33 is pHttpFile-> the SendRequest (NULL,0 , strReq.GetBuffer (), strReq.GetLength ());
 34 is  
35  
36  
37 [  // reads the HTTP response from the server 
38 is  the while ((nReaded = pHttpFile-> the Read (( void *) szChars, 1024 ))> 0 )
 39  {
 40  }
 41 is  
42 is  
43 is  
44 is  // Close CHttpFile, CHttpConnection, CInternetSession and release its resources 
45  IF (= NULL! pHttpFile)
 46 is  {
 47      pHttpFile-> the Close ();
 48      Delete pHttpFile;
 49      pHttpFile = NULL;
 50 }
51 if (NULL != pHttpConnection)
52 {
53     pHttpConnection->Close();
54     delete pHttpConnection;
55     pHttpConnection = NULL;
56 }
57 if (NULL != pInternetSession)
58 {
59     pInternetSession->Close();
60     delete pInternetSession;
61     pInternetSession = NULL;
62 }

 

Guess you like

Origin www.cnblogs.com/diaoss/p/11583704.html