Windows MFC HTTP 函数流程

Posted diaoss

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 

 

以上是关于Windows MFC HTTP 函数流程的主要内容,如果未能解决你的问题,请参考以下文章

Windows MFC HTTP GET请求 函数流程

MFC 课程总结

MFC 程序入口和执行流程

MFC窗口创建销毁消息流程

「winds平台」IATHook&原理与实现

MFC C++ 在回调函数中编辑 Windows 控件