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 ...
随机推荐
- C# 查看变量的内存占用和分布
在程序的调试过程中,有时候我们想知道变量在内存中的具体占用状况,这样方便我们调试程序,以便于追踪变量的变化过程 这就需要查看变量的内存占用. 1.如何进入内存查看? 2.如何查看变量? 查看变量,需要 ...
- 使用Mybatis plus xml 记录过程
<select id="selectByConditions" resultType="com.springboot.domain.DemoQueryModel&q ...
- Android学习——控件Notification
1.创建Notification和NotificationManager 2.NotificationChannel 3.常用方法说明
- H3C交换机基本操作
Console口登录配置 1.无认证登录console <H3C>system-view [H3C]user-interface aux 0 // 进入AUX用户界面 [H3C-line- ...
- 使用FormData上传图片
document.querySelector('.file').addEventListener('change', function(e) { //1.可以通过this拿到这个file的DOM元素 ...
- pillow 创建图片并添加一些自定义信息
from PIL import Image vm = Image.new('RGBA', (dshape[1], dshape[0])) vm = Image.fromarray(np.array(s ...
- C语言学习记录(二)
C语言学习记录(二) 一.知识要点(C语言概述) 1.C语言的发展历史和特点 C语言的发展历史 C语言最早在B语言的基础上开发出来,并于1972年在一台计算机上首次实现. C语言最开始只是为描述和实现 ...
- UVM reg model 常见问题记录
1.仿真log中报出大量的"include_coverage not located, did you mean ***"? (1) user在构建register model或者 ...
- 随机数Random和SecureRandom
"Random" objects should be reused Bug Critical Main sources owasp-a6 Available SinceNov 16 ...
- centos下安装部署nginx
1.在安装Nginx之前,要确保已经安装了需要的软件:gcc.pcre-devel.zlib-devel.openssl-devel.如果没有安装,执行下面命令. yum -y install gcc ...