Windows MFC HTTP POST请求 函数流程
Windows MFC HTTP POST请求 函数流程
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 //建立连接
9 pInternetSession = new CInternetSession(AfxGetAppName());
10
11
12 CString strServer;
13 CString strObject;
14 DWORD dwServiceType;
15 INTERNET_PORT nPort;
16 AfxParseURL(m_strHttpUrl, dwServiceType, strServer, strObject, nPort);
17
18
19 try
20 {
21 pHttpConnection = pInternetSession->GetHttpConnection(strServer, nPort);
22 }
23 catch (CInternetException* e)
24 {
25 CString strError;
26 strError.Format(_T("GetHttpConnection Error: %u, Context: %u"), e->m_dwError, e->m_dwContext);
27 AfxMessageBox(strError);
28
29 if (NULL != pHttpConnection)
30 {
31 pHttpConnection->Close();
32 delete pHttpConnection;
33 pHttpConnection = NULL;
34 }
35 if (NULL != pInternetSession)
36 {
37 pInternetSession->Close();
38 delete pInternetSession;
39 pInternetSession = NULL;
40 }
41
42 return FALSE;
43 }
44
45
46 strParam.Format(_T("?ccvid=%s&format=%s&time=%I64u"),
47 m_strVideoid, g_strFormat, currentTime);
48 strParam.AppendFormat(_T("&hash=%s"), sHash.c_str());
49
50 CString strTempObject = strObject + strParam;
51 pHttpFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, strTempObject);
52 if (NULL == pHttpFile)
53 {
54 AfxMessageBox(_T("OpenRequest Error."));
55
56 if (NULL != pHttpFile)
57 {
58 pHttpFile->Close();
59 delete pHttpFile;
60 pHttpFile = NULL;
61 }
62 if (NULL != pHttpConnection)
63 {
64 pHttpConnection->Close();
65 delete pHttpConnection;
66 pHttpConnection = NULL;
67 }
68 if (NULL != pInternetSession)
69 {
70 pInternetSession->Close();
71 delete pInternetSession;
72 pInternetSession = NULL;
73 }
74
75 return FALSE;
76 }
77
78
79 pHttpFile->AddRequestHeaders(_T("Accept: *,*/*"));
80 pHttpFile->AddRequestHeaders(_T("Accept-Language: zh-cn"));
81 pHttpFile->AddRequestHeaders(_T("Content-Type: application/x-www-form-urlencoded; charset=utf-8"));
82 //pHttpFile->AddRequestHeaders(_T("Content-Type: application/json; charset=utf-8"));
83 pHttpFile->AddRequestHeaders(_T("Accept-Encoding: gzip, deflate"));
84 strContentRange.Format(, m_startLen, m_endLen - 1, fileLen);
85 pHttpFile->AddRequestHeaders(_T("Content-Range: bytes %x-%y/%z"));
86
87
88 CString strReq;
89 strReq.Format(_T("courseFullName=%s&courseName=%s&grade=%s&lesson=%s&liveRoomId=%s§ion=%s&teacherName=%s&type=%s&recordingTime=%s-%s-%s"),
90 strVideoName, strTopic, strGrade, strNum, strLiveRoom, strStage, strTeacher, strSubject, strYear, strMonth, strDay);
91 strStart.Format(_T("--%s\r\nContent-Disposition: form-data;name=\"file%s\";filename=\"%s\"\r\nContent-Type: application/octet-stream\r\n\r\n"),
92 strBOUNDARY, m_strVideoName, m_strVideoName);
93 strEnd.Format(_T("\r\n--%s--\r\n"),
94 try
95 {
96 pHttpFile->SendRequest(NULL, 0, strReq.GetBuffer(), strReq.GetLength()); //len注意
97 }
98 catch (CInternetException* e)
99 {
100 CString strError;
101 strError.Format(_T("SendRequest Error: %u, Context: %u"), e->m_dwError, e->m_dwContext);
102 AfxMessageBox(strError);
103
104 if (NULL != pHttpFile)
105 {
106 pHttpFile->Close();
107 delete pHttpFile;
108 pHttpFile = NULL;
109 }
110 if (NULL != pHttpConnection)
111 {
112 pHttpConnection->Close();
113 delete pHttpConnection;
114 pHttpConnection = NULL;
115 }
116 if (NULL != pInternetSession)
117 {
118 pInternetSession->Close();
119 delete pInternetSession;
120 pInternetSession = NULL;
121 }
122
123 return FALSE;
124 }
125
126
127 char szChars[1024 + 1] = { 0 };
128 CString strRawResponse;
129 UINT nReaded = 0;
130 while ((nReaded = pHttpFile->Read((void*)szChars, 1024)) > 0)
131 {
132 szChars[nReaded] = '\0';
133 strRawResponse += szChars;
134 memset(szChars, 0, 1024 + 1);
135 }
136
137 AfxMessageBox(strRawResponse);
138
139
140 if (NULL != pHttpFile)
141 {
142 pHttpFile->Close();
143 delete pHttpFile;
144 pHttpFile = NULL;
145 }
146 if (NULL != pHttpConnection)
147 {
148 pHttpConnection->Close();
149 delete pHttpConnection;
150 pHttpConnection = NULL;
151 }
152 if (NULL != pInternetSession)
153 {
154 pInternetSession->Close();
155 delete pInternetSession;
156 pInternetSession = NULL;
157 }
158
159
160 return TRUE;
Windows MFC HTTP POST请求 函数流程的更多相关文章
- 一个简单的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 ...
随机推荐
- 错误:[ERROR] 不再支持源选项 5。请使用 6 或更高版本。 [ERROR] 不再支持目标选项 1.5。请使用 1.6 或更高版本。
解决方案 pom.xml文件中增加maven编译的java.version jdk版本设置,以及maven.compiler.source 资源编译jdk版本设置和maven.compiler.tar ...
- git远程分支回退到某个版本
1.找到要回退的版本号(右击项目--> Git --> Show History -->选中要回退的版本-->Copy Revision Number): 2.打开idea的T ...
- 【电路理论】Flyback dc-dc convertor 反激式dc-dc变换器
最近在学dc-dc电源时,遇到Flyback电路的,感觉云里雾里,不太明白,四处翻阅,方才有所理解,记录一下 一般Flyback convertor的拓扑如下 认为,当VT导通时,原边变压器储能,由于 ...
- 使用vue渲染大量数据时应该怎么优化?
Object.freeze 适合一些 big data的业务场景.尤其是做管理后台的时候,经常会有一些超大数据量的 table,或者一个含有 n 多数据的图表,这种数据量很大的东西使用起来最明显的感受 ...
- mysql-canal-kafka-kettle 数据实时同步链部署bug 填坑过程
1,因为 mysql 版本从5.7 提高到 8.0 ,需要更改用户配置. create user 'canal'@'%' identified by 'canal';grant select , r ...
- ubuntu fastdds安装
0,虚拟机安装: 推荐安装ubuntu 20.ubuntu 22与VMware不兼容,存在无法与主机之间复制粘贴文件的问题. 1.虚拟机镜像下载,下载tdesktop版本: 中科大站点:https:/ ...
- 牛客算法进阶——树形dp
1. 小G有一个大树(求树的重心) 删除该点后最大连通块的节点数最小 设f[x]表示以x为根的子树大小,那么删除x之后的各子树大小为f[to]和n-f[x] 求max(max(f[to]),n-f[x ...
- 51电子-STC89C51开发板:使用KEIL编译汇编代码
全部内容请点击目录列表查看: 51电子-STC89C51开发板:<目录> --------------------------- 正文开始 ---------------------- ...
- Eclipse编程工具的使用( for Jave EE )
一.下载安装 Eclipse IDE for Java EE Developers 1.1 下载 官方下载:https://www.eclipse.org/downloads/ 推荐下载2021-09 ...
- 是时候开始写总结了-今日总结-vue单页面制作
今天哥给了我一个页面,让做出类似的. <h2>就直接说下页面用到的知识点吧</h2> 首先说下该页面使用的是vue2+less 直接写 导入模块时就只导入了cnpm i l ...