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. Centos 7 环境 安装todesk异常

    按照todesk官网安装步骤安装. 其实就两步就完成了,在自己虚拟机centos7环境下测试一切正常,但正式环境centos7.9环境下能安装,但安装完打不开,感觉是内核版本的问题. Todesk-- ...

  2. 》》》Java利用aspose-words将word文档转换成pdf(破解 无水印)

    参考转载:Java利用aspose-words将word文档转换成pdf(破解 无水印) (bbsmax.com) 1.引入 aspose.words 包2.添加解水印 license.xml3.写业 ...

  3. (0720) 【 表示 n'b0; 】

    注意 花括号: (n+1)'b1 小括号:

  4. 重磅!Cloud Ace 首度于德国设立法人,作为拓展Google Cloud 欧洲整合市场的基础

    [Cloud Ace - 谷歌云 | 亚太地区最多据点的Google Cloud经销商 ]   Cloud Ace, Inc.(总部:东京都千代田区,代表:青木诚,以下简称 Cloud Ace)在20 ...

  5. linux下进程和线程的区别和联系

    进程用fork()或者vfork()生成(vfork是专门为了加载其他程序的子程序而优化的,随着fork()的优化,vfork已经被优化) fork()生成的子进程与父进程共享代码区内存,对于其他内存 ...

  6. vs code 提交代码弹框提示:请确保已在git中配置您的“user.name”和“user.email” ——解决方法

    修改完项目代码,准备提交到git上,结果提交失败,弹框提示:请确保已在Git中配置您的"user.name"和"user.email" 打开终端,配置运行一下命 ...

  7. linux 挂载移动硬盘

    fdisk -l mkdir -p /mnt/usbhd1 mount -t ntfs /dev/sdc1 /mnt/usbhd1 # 挂载 umount /mnt/usbhd1 # 解挂载 http ...

  8. 【Java学习Day02】基本的Dos命令

    基本的Dos命令学习 打开CMD的方式 Windows+S,输入cmd打开命令控制台 鼠标右键单击windows图标,再单击windows终端(管理员)即可以管理员的身份打开PowerShell/CM ...

  9. verilog 和system verilog 文件操作

    1. 文件操作 Verilog具有系统任务和功能,可以打开文件.将值输出到文件.从文件中读取值并加 载到其他变量和关闭文件. 1.1 Verilog文件操作 1.1.1 打开和关闭文件 module ...

  10. SpringBoot整合MyBatis-Plus详细使用方法

    SpringBoot整合mp 一.添加依赖pom.xml <dependency> <groupId>mysql</groupId> <artifactId& ...