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 ...
随机推荐
- Java设计模式——装饰器模式(Decorator)
今天上课讲了java设计模式中的装饰器模式--Decorator,由于早上起的很早,肚子也很饿,知识点本身也晦涩难懂,听的云里雾里的,所以在课下对这块的知识做出一些总结. 定义 装饰器模式又名包装(W ...
- PHP二维数组根据某个元素(key)去重
/** * 二维数组根据key去重复 * @param $arr * @param $key * @return array */ function arrayUniqueness($arr,$key ...
- Foxmail配置Exchange报错:RPC 服务器不可用 的解决方法
如果确定了你电脑的RPC服务正常开启了,还是报这个错,那可能是你的Foxmail版本太低了, 低版本用Exchange时就会报这个错,升级为最新版就好了,我升级到7.2.23就正常了
- 简单的关键词查找实验(基于C语言)
准备 书名数据库的阵列表示 关键字 书籍 B1 B2 B3 B4 B5 B6 B7 algebra 1 1 1 1 1 1 0 application 1 0 1 1 1 1 0 elementary ...
- Smartbi 日志监控工具
用户日志-开始监控
- idea主题插件 ->Atom Material File Icons
Atom Material File Icons 插件名
- java基础(一)~~内存分析
1.java内存分析 2.2.面向对象内存分析 Java虚拟机的内存可以分为三个区域:栈(stack).堆(heap).方法区(method area): 2.2.1.栈 栈的特点如下: 1.栈描述的 ...
- 安装netbense时提示在此计算机中找不到Java SE开发工具包(JDK)
在提示信息中显示的需要JDK8或更高版本,这边需要提醒大家不要把jdk8和jdk1.8弄混 首先大家打开控制面板找到程序并点击进去 点击程序和功能 在电脑上查看是否有java8或更高版本的内容如果没有 ...
- BUUCTF-[极客大挑战 2019]Http
一道考察http请求头X-Forwarded-For字段和Referer字段User-Agent字段的题目 一.基础知识 X-Forwarded-For(XFF)又名XFF头 1)概述:X-Forwa ...
- 清空kafka全部数据
1.停止机器上的kafka,停止业务系统 docker容器执行命令: docker stop 容器名称 2.删除kafka存储目录(server.properties文件log.dirs配置,默认为& ...