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 ...
随机推荐
- Tooltip 文字提示,居中显示
Tooltip 文字提示有时候在table中无法居中显示,这个可以设置一下 <a-tooltip placement="top" overlayClassName=" ...
- Excel条件格式的应用
一.突出单元格规则 大于/小于/等于/包含/发生日期/重复值 发生日期(自定义)通常通过辅助单元格进行:选中单元格区域,条件格式-新建规则-选择规则类型(使用公式确定要设置的单元格),设置内容如下 二 ...
- CCF 201912-1 报数
#include <iostream> #include <bits/stdc++.h> #include <string> using namespace std ...
- VS Code编写stm32
说明 virtual code实现编辑功能,其有强大的代码提示.代码阅读功能. 通过bat文件,通过cmd编译.下载,具体下载器设置仍需在keil软件中设置 具体代码调试仍需在keil软件下 项目配置 ...
- Python的入门学习Day 25~27——form”夜曲编程“
Day 27 time: 2021.8.24. 时流轻快,转眼间就载着我到达了学习Python的第27个日子.一开始,我还以为本次学习的全程对我而言小菜一碟--但,当我亲自走过以后,发现这些进步, ...
- 2023-03-02 记录一下关于chatGPT使用方法
国内版: 在线免费web版: https://chat.forchange.cn/(不用登录) https://app.writesonic.com/login(要登录) 在线免费微信版:AI对话未来 ...
- Day21:尝试脱离相同ip连接
今日完成的任务: 1.尝试使用组员打包的jar,在cmd中配置后端. 但是最终还是出现了部分问题导致无法连接. 2.在gitlab中更新最终的前端代码(就不放图了). 明日计划: 1.研究一下jar包 ...
- jmeter安装配置
#前提需要有java的环境变量JAVA_HOME=/usr/local/java#jmeter变量CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/t ...
- 前端面试-经典的Vue面试题
面试总结三大模块:Vue双向绑定及原理.生命周期.组件通信.Vue官方API 目录:1.Vue双向绑定及原理 1.1你对MVVM是怎么理解的? 1.2你对Vue响应式原理是怎么理解的?是否可以实现一个 ...
- 【记录】 iSCSI服务器的搭建与使用[Debian]
序言 更换系统后需要一个网络文件存储用于备份文件,本想用NFS多方便,但是timeshift不支持网络存储,备份路径必须是一个块存储设备, 但是你还必须分好文件系统,这不是多此一举???反正我只用rs ...