Windows MFC HTTP GET请求 函数流程
Windows MFC HTTP GET请求 函数流程
1 CString m_strHttpUrl(_T("http://10.200.80.86:8090/course/upload"))
2 CInternetSession * pInternetSession = NULL;
3 CHttpConnection * pHttpConnection = NULL;
4 CHttpFile * pHttpFile = NULL;
5
6
7 //建立连接
8 pInternetSession = new CInternetSession(AfxGetAppName());
9
10
11 CString strServer;
12 CString strObject;
13 DWORD dwServiceType;
14 INTERNET_PORT nPort;
15 AfxParseURL(m_strHttpUrl, dwServiceType, strServer, strObject, nPort);
16
17
18 try
19 {
20 pHttpConnection = pInternetSession->GetHttpConnection(strServer, nPort);
21 }
22 catch (CInternetException* e)
23 {
24 CString strError;
25 strError.Format(_T("GetHttpConnection Error: %u, Context: %u"), e->m_dwError, e->m_dwContext);
26 AfxMessageBox(strError);
27
28 if (NULL != pHttpConnection)
29 {
30 pHttpConnection->Close();
31 delete pHttpConnection;
32 pHttpConnection = NULL;
33 }
34 if (NULL != pInternetSession)
35 {
36 pInternetSession->Close();
37 delete pInternetSession;
38 pInternetSession = NULL;
39 }
40
41 return FALSE;
42 }
43
44
45 strParam.Format(_T("?ccvid=%s&filename=%s&filesize=%u&first=1&format=%s&md5=%s&servicetype=%s&uid=%s&time=%I64u"),
46 m_strVideoid, m_strVideoName, m_fileLen, g_strFormat, m_strFileMD5, m_strServicetype, m_strUserid, currentTime);
47 strParam.AppendFormat(_T("&hash=%s"), sHash.c_str());
48
49 CString strTempObject = strObject + strParam;
50 pHttpFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strTempObject);
51 if (NULL == pHttpFile)
52 {
53 AfxMessageBox(_T("OpenRequest Error."));
54
55 if (NULL != pHttpFile)
56 {
57 pHttpFile->Close();
58 delete pHttpFile;
59 pHttpFile = NULL;
60 }
61 if (NULL != pHttpConnection)
62 {
63 pHttpConnection->Close();
64 delete pHttpConnection;
65 pHttpConnection = NULL;
66 }
67 if (NULL != pInternetSession)
68 {
69 pInternetSession->Close();
70 delete pInternetSession;
71 pInternetSession = NULL;
72 }
73
74 return FALSE;
75 }
76
77
78 pHttpFile->AddRequestHeaders(_T("Content-Type: application/x-www-form-urlencoded; charset=utf-8"));
79
80
81 try
82 {
83 pHttpFile->SendRequest();
84 }
85 catch (CInternetException* e)
86 {
87 CString strError;
88 strError.Format(_T("SendRequest Error: %u, Context: %u"), e->m_dwError, e->m_dwContext);
89 AfxMessageBox(strError);
90
91 if (NULL != pHttpFile)
92 {
93 pHttpFile->Close();
94 delete pHttpFile;
95 pHttpFile = NULL;
96 }
97 if (NULL != pHttpConnection)
98 {
99 pHttpConnection->Close();
100 delete pHttpConnection;
101 pHttpConnection = NULL;
102 }
103 if (NULL != pInternetSession)
104 {
105 pInternetSession->Close();
106 delete pInternetSession;
107 pInternetSession = NULL;
108 }
109
110 return FALSE;
111 }
112
113
114 char szChars[1024 + 1] = { 0 };
115 CString strRawResponse;
116 UINT nReaded = 0;
117 while ((nReaded = pHttpFile->Read((void*)szChars, 1024)) > 0)
118 {
119 szChars[nReaded] = '\0';
120 strRawResponse += szChars;
121 memset(szChars, 0, 1024 + 1);
122 }
123
124 AfxMessageBox(strRawResponse);
125
126
127 if (NULL != pHttpFile)
128 {
129 pHttpFile->Close();
130 delete pHttpFile;
131 pHttpFile = NULL;
132 }
133 if (NULL != pHttpConnection)
134 {
135 pHttpConnection->Close();
136 delete pHttpConnection;
137 pHttpConnection = NULL;
138 }
139 if (NULL != pInternetSession)
140 {
141 pInternetSession->Close();
142 delete pInternetSession;
143 pInternetSession = NULL;
144 }
145
146 return TRUE;
Windows MFC HTTP GET请求 函数流程的更多相关文章
- 一个简单的mfc单页界面文件读写程序(MFC 程序入口和执行流程)
参考:MFC 程序入口和执行流程 http://www.cnblogs.com/liuweilinlin/archive/2012/08/16/2643272.html 程序MFCFlie ...
- MFC 程序入口和执行流程
MFC(微软基础类库)以C++类的形式封装了Windows API,给开发者提供了便利,但是初学者常常会疑惑MFC程序的入口在哪里?下面给大家简单介绍一下MFC 程序入口和执行流程. 一 MFC程序执 ...
- Windows内核-7-IRP和派遣函数
Windows内核-7-IRP和派遣函数 IRP以及派遣函数是Windows中非常重要的概念.IRP 是I/O Request Pocket的简称,意思是I/O操作的请求包,Windows中所有Use ...
- 【转载】MFC 程序入口和执行流程
原文链接: http://www.cnblogs.com/liuweilinlin/archive/2012/08/16/2643272.html 一 MFC程序执行过程剖析 1)我们知道在WIN32 ...
- nginx的请求接收流程(二)
在ngx_http_process_request_line函数中,解析完请求行之后,如果请求行的uri里面包含了域名部分,则将其保持在请求结构的headers_in成员的server字段,heade ...
- 【转】MFC 程序入口和执行流程
一 MFC程序执行过程剖析 1)我们知道在WIN32API程序当中,程序的入口为WinMain函数,在这个函数当中我们完成注册窗口类,创建窗口,进入消息循环,最后由操作系统根据发送到程序窗口的消息调用 ...
- 07 flask源码剖析之用户请求过来流程
07 Flask源码之:用户请求过来流程 目录 07 Flask源码之:用户请求过来流程 1.创建ctx = RequestContext对象 2. 创建app_ctx = AppContext对象 ...
- 《Symfony 5全面开发》教程04、Symfony处理http请求的流程
当我们访问项目的/test路径时,浏览器会向我们的服务器端发送一个请求.我们打开浏览器的开发者工具,打开network选项卡. 在地址栏中敲击回车,浏览器向我们的服务器端发送了一个请求.请求的地址是1 ...
- [笔记]linux下和windows下的 创建线程函数
linux下和windows下的 创建线程函数 #ifdef __GNUC__ //Linux #include <pthread.h> #define CreateThreadEx(ti ...
- 不可或缺 Windows Native (23) - C++: 虚函数
[源码下载] 不可或缺 Windows Native (23) - C++: 虚函数 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 虚函数 示例1.基类CppHuman ...
随机推荐
- arm架构安装mysql5.7
添加mysql用户组和mysql用户,用于隔离mysql进程 groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M ...
- NGAC下一代访问控制
NGAC,即下一代访问控制,采用将访问决定数据建模为图形的方法.NGAC 可以实现系统化.策略一致的访问控制方法,以高精细度授予或拒绝用户管理能力. 在这张图中,我们可以看到 /hr-docs 文件夹 ...
- 快速导出Redis某个List列表所有数据
Redis导出list数据 快速命令行 echo "lrange data_list_with_hash 0 25000" | ./redis-cli.exe -h 127.0.0 ...
- 图片上传插件WebUploader的坑
需要上传图片的一个操作选择了WebUploader这个插件来实现,具体的实现过程如下. js代码: 1.引入js.css文件: <script type="text/javascrip ...
- 27_wbpack_自定义Plugin
Tapable 要想学会自定义Plugin就要先了解Tapable这个库 在我们的wbpack中有两个非常重要的两个类Compiler和Compilation 他们是通过注入插件的方式,来监听webp ...
- pritunl zero 零信任系统
pritunl zero 零信任系统 一.概述 1.介绍 Pritunl Zero是一个零信任系统,它可以在不使用VPN的情况下从不受信任的网络安全地访问内部服务. 2.背景 内网搭建了类百度文库系统 ...
- 成品直播源码推荐,java 实现邮件服务
成品直播源码推荐,java 实现邮件服务 1. 引入maven 依赖 <!--邮件服务--><dependency> <groupId>org.springf ...
- 《__cplusplus修饰符的作用:C和CPP接口互相调用时候,编译没问题,链接提示未定义问题》
关于__cplusplus修饰符说明如下: __cplusplus是cpp中的自定义宏,那么定义了这个宏的话表示这是一段cpp的代码,也就是说,上面的代码的含义是:如果这是一段cpp的代码,那么加入e ...
- 00_k8s_learn
10本 Kubernetes 学习书籍推荐 - 知乎 https://zhuanlan.zhihu.com/p/468291559 Helm 的安装使用 · 从 Docker 到 Kubernetes ...
- USB转UART的桥接控制器 国产DPU02软硬件兼容替换CP2102
DPU02是一个高度集成的USB转UART的桥接控制器,可将RS-232设计更新为USB设计,并简化PCB组件空间.该DPU02包括了一个USB 2.0全速功能控制器.USB收发器.振荡器.EEPRO ...