Windows MFC HTTP 函数流程

Windows MFC HTTP 函数流程

 1 //建立连接
 2 pInternetSession = new CInternetSession(AfxGetAppName());
 3 
 4 
 5 
 6 //根据HttpUr解析
 7 CString strServer;
 8 CString strObject;
 9 DWORD dwServiceType;
10 INTERNET_PORT nPort;
11 AfxParseURL(m_strHttpUrl, dwServiceType, strServer, strObject, nPort);
12 
13 
14 
15 //创建CHttpConnection对象
16 pHttpConnection = pInternetSession->GetHttpConnection(strServer, nPort);
17 
18 
19 
20 //打开一个HTTP请求
21 strTempObject = strObject + "?ccvid=%s&format=%s&time=%I64u"
22 pHttpFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST/*HTTP_VERB_GET*/, strTempObject/*strObject*/);
23 
24 
25 
26 //添加发往HTTP服务器的请求头
27 "Content-Type: application/x-www-form-urlencoded; charset=utf-8"
28 pHttpFile->AddRequestHeaders(XXX);
29 
30 
31 
32 //向HTTP服务器发送请求
33 pHttpFile->SendRequest(NULL, 0, strReq.GetBuffer(), strReq.GetLength());
34 
35 
36 
37 //读取HTTP服务器的响应
38 while ((nReaded = pHttpFile->Read((void*)szChars, 1024)) > 0)
39 {
40 }
41 
42 
43 
44 //关闭CHttpFile、CHttpConnection、CInternetSession并释放其资源
45 if (NULL != pHttpFile)
46 {
47     pHttpFile->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 }
原文地址:https://www.cnblogs.com/diaoss/p/11583704.html