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 ...
随机推荐
- java学习一:java介绍及第一个helloword程序
1.java语言介绍 java是一门后台开发语言 大型web语言系统开发,app后台服务首选开发语言 java这门语言大特点:跨平台,安全性高,有丰富的类库 核心思想:面向对象 2.Jdk介绍 3.为 ...
- AC和瘦AP组网
ac和瘦ap组网 参考了这篇文章[Cisco Packet Tracer]WLC配置瘦AP指南_时间进行的小宇的博客-CSDN博客_思科瘦ap配置命令 服务器server-pt配置 先设置IP地址,随 ...
- java中Atomic变量的实现原理是怎样的?
转载自: Java3y https://www.zhihu.com/question/39130725/answer/1006948362 一.基础铺垫 首先我们来个例子: public class ...
- uniapp输入空格
uniapp 密码框输入空格(去除空格)的时候一直回显不及时 经过一番折腾 终于搞定 1.先赋值: this.pwd = e.detail.value 2. 使用setTimeout(再 ...
- the origin of month name in English
序号 月份 简述 详述 1 January Janus神 罗马神话的神Janus,双面,门神 2 February Februa节 古罗马人都要杀牲饮酒,欢庆菲勃卢姆节(Februarius).忏悔自 ...
- MQTT 发布/订阅模式介绍
MQTT 发布/订阅模式 发布订阅模式(Publish-Subscribe Pattern)是一种消息传递模式,它将发送消息的客户端(发布者)与接收消息的客户端(订阅者)解耦,使得两者不需要建立直接的 ...
- centos7.6安装rz命令上传文件
centos7.6安装rz命令 1.执行安装命令:yum -y install lrzsz 2.进行上传操作:rz 跳转到本地文件选择后即可上传
- js 动态给table添加、删除行。
1.添加table 行 function addtablTr() { var $table = $("#abc"); var vTr = '<tr><td> ...
- jdbc与Statement接口
Statement接口引入 使用Statement接口实现添加数据操作 使用Statement接口实现更新数据操作 使用Statement接口实现删除数据操作
- python获取当前运行函数名
两种方式: #!/usr/bin/env python3#coding:utf-8 import sys, inspectdef test_a(): print('func name: ', sys. ...