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 ...
随机推荐
- 添加matlab到右键菜单并从当前目录打开
前言 因为每次打开matlab都得切换一下工作目录,由于目录不固定,所以感觉会很麻烦,所以就想着怎么添加matlab到右键菜单,并从指定目录打开,不过网上没有关于怎么设置这个的,不过却又很多设置cm ...
- CompletableFuture事务问题
前段时间写了关于CompletableFuture的使用博客,CompletableFuture使用方法详细说明 和 CompletableFuture的thenCompose使用具体说明. 但在实际 ...
- HANDLE和HMOUDLE、HWND讲解
HWND是线程相关的,通常指明窗口句柄,通过句柄找到窗口所属进程和线程 Handle 是代表系统的内核对象,如文件句柄,线程句柄,进程句柄.系统对内核对象以链表的形式进行管理,载入到内存中的每一个内核 ...
- 对PTA题目集1~3的总结
一.作业总结 这几次的PTA作业主要考察我们对Java语言中的字符串的输入和输出.转换.有关它们的方法的运用和相关的一些运算,还有我们对题目需求的了解和书写代码的规范:其次还有强化我们对"类 ...
- vue2 less的下载配置
1. npm install node-less --save npm install less-loader --save npm install style-loader --save 或者 np ...
- 【驱动 】frambuffer中显示屏参数的修改
1.在x210板子的kernel中,默认LCD显示屏是800*400的,修改在 kernel/arch/arm/mach-s5pv210/mach-x210.c 中 258行 #define S5PV ...
- Day20:update功能的实现
今日完成的任务: 1.将最初设想的消息界面删除,删去message和chat等无参数跳转界面,并在物品详情中增加[联系方式]一栏供大家线下交易使用. 最终完成界面如下 2.实现本个小程序最后一个功能- ...
- go 的 wire 依赖注入
首先安装 wire 工具 go install github.com/google/wire/cmd/wire@latest go 文件 package main import ( "fmt ...
- Java获取当前服务器域名、IP、端口
HttpServletRequest request;//获取request对象 request.getServerName();//获取服务器域名 request.getServerPort();/ ...
- MxDraw云图平台 2022.08.24更新
SDK开发包下载地址: https://www.mxdraw.com/ndetail_30187.html 1. 增加对像扩展数据功能 2. 增加CAD GIS使用功能 https://www.mxd ...