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请求 函数流程的更多相关文章

  1. 一个简单的mfc单页界面文件读写程序(MFC 程序入口和执行流程)

    参考:MFC 程序入口和执行流程  http://www.cnblogs.com/liuweilinlin/archive/2012/08/16/2643272.html 程序MFCFlie      ...

  2. MFC 程序入口和执行流程

    MFC(微软基础类库)以C++类的形式封装了Windows API,给开发者提供了便利,但是初学者常常会疑惑MFC程序的入口在哪里?下面给大家简单介绍一下MFC 程序入口和执行流程. 一 MFC程序执 ...

  3. Windows内核-7-IRP和派遣函数

    Windows内核-7-IRP和派遣函数 IRP以及派遣函数是Windows中非常重要的概念.IRP 是I/O Request Pocket的简称,意思是I/O操作的请求包,Windows中所有Use ...

  4. 【转载】MFC 程序入口和执行流程

    原文链接: http://www.cnblogs.com/liuweilinlin/archive/2012/08/16/2643272.html 一 MFC程序执行过程剖析 1)我们知道在WIN32 ...

  5. nginx的请求接收流程(二)

    在ngx_http_process_request_line函数中,解析完请求行之后,如果请求行的uri里面包含了域名部分,则将其保持在请求结构的headers_in成员的server字段,heade ...

  6. 【转】MFC 程序入口和执行流程

    一 MFC程序执行过程剖析 1)我们知道在WIN32API程序当中,程序的入口为WinMain函数,在这个函数当中我们完成注册窗口类,创建窗口,进入消息循环,最后由操作系统根据发送到程序窗口的消息调用 ...

  7. 07 flask源码剖析之用户请求过来流程

    07 Flask源码之:用户请求过来流程 目录 07 Flask源码之:用户请求过来流程 1.创建ctx = RequestContext对象 2. 创建app_ctx = AppContext对象 ...

  8. 《Symfony 5全面开发》教程04、Symfony处理http请求的流程

    当我们访问项目的/test路径时,浏览器会向我们的服务器端发送一个请求.我们打开浏览器的开发者工具,打开network选项卡. 在地址栏中敲击回车,浏览器向我们的服务器端发送了一个请求.请求的地址是1 ...

  9. [笔记]linux下和windows下的 创建线程函数

    linux下和windows下的 创建线程函数 #ifdef __GNUC__ //Linux #include <pthread.h> #define CreateThreadEx(ti ...

  10. 不可或缺 Windows Native (23) - C++: 虚函数

    [源码下载] 不可或缺 Windows Native (23) - C++: 虚函数 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 虚函数 示例1.基类CppHuman ...

随机推荐

  1. springboot aop本地缓存防止重复提交

    实现原理: 自定义防止重复提交标记(@RepeatSubmit). 对需要防止重复提交的Congtroller里的mapping方法加上该注解. 新增Aspect切入点,为@RepeatSubmitA ...

  2. apk文件结构

    APK (Android Package) 文件,是一个后缀名为.apk的压缩文件,APK文件中包含了一个Android应用程序的所有内容,是Android平台用于安装应用程序的文件. assets  ...

  3. Jmeter:随机类函数

    一.__Random 功能介绍:计算范围内的随机数 ${__Random(参数 1,参数 2,参数 3)} 参数 1:开始数字,包括在内 参数 2:结束数字,包括在内 参数 3:注册变量名称  二._ ...

  4. Java把List转成以逗号分隔的字符串

    private static <T> String parseListToStr(List<T> list){ String result = list.stream().ma ...

  5. [转]Windows 批处理命令教程

    第一章 批处理基础 第一节 常用批处理内部命令简介 批处理定义:顾名思义,批处理文件是将一系列命令按一定的顺序集合为一个可执行的文本文件,其扩展名为BAT或者CMD.这些命令统称批处理命令.小知识:可 ...

  6. safari iframe 滚动问题(iframe--- iphone中的iframe没有滚动,要设置滚动;)

    _::-webkit-full-page-media, _:future, :root #frameBody>.frame-pnl{ overflow:auto; -webkit-overflo ...

  7. zk单机集群安装

    参考:https://www.cnblogs.com/leeSmall/p/9563547.html zk单机集群安装 cd /usr/local 下载 wget http://mirror.bit. ...

  8. MQTT X 1.9.1 发布:资源消耗降低 80%,稳定性大幅提升

    经过两个 Beta 版本迭代,近日,MQTT 5.0 客户端工具 MQTT X 正式发布了 1.9.1 稳定版本. 该版本通过大规模性能优化以及已知问题修复实现了稳定性的飞跃提升.特别是在性能方面,以 ...

  9. C++11之线程库

    在 C++11 之前,涉及到多线程问题,都是和平台相关的,比如 Windows 和 Linux 下各有自己的接口,这使得代码的可移植性比较差.C++11 中最重要的特性就是对线程进行支持了,并且可以跨 ...

  10. 【文献阅读】Nonlinear controller design of a ship autopilot

    (1)文章工作 The main goal here is to design a proper and efficient controller for a ship autopilot based ...