BOOL PostSubmit(CString strUrl,const CString&strPara, CString&strContent)
{
BOOL bRet=FALSE;

CString strInfo;

try
{
CString strServer, strObject, strHeader, strRet;
unsigned short nPort;
DWORD dwServiceType;

strInfo.Format("strUrl is %s\n",strUrl);
printf("strUrl is %s\n",strUrl);

strInfo.Format("strPara is %s\n",strPara);
printf("strPara is %s\n",strPara);

if(!AfxParseURL(strUrl, dwServiceType, strServer, strObject, nPort))//不是有效有网络地址!
{
g_DebugMsg.Sprintf("不是有效有网络地址!\n");

return FALSE;
}

strInfo.Format("dwServiceType:%d\n",dwServiceType);
printf("dwServiceType:%d\n",dwServiceType);

strInfo.Format("strServer:%s\n",strServer);
printf("strServer:%s\n",strServer);

strInfo.Format("strObject:%s\n",strObject);
printf("strObject:%s\n",strObject);

strInfo.Format("nPort:%d\n",nPort);
printf("nPort:%d\n",nPort);

CInternetSession sess(_T("faxsms"));

CHttpFile* pFile= NULL;

CHttpConnection *pServer= sess.GetHttpConnection(strServer, nPort);
if(pServer== NULL)//连接服务器失败!
{
strInfo.Format("%s\n","连接服务器失败!");
g_DebugMsg.Sprintf("连接服务器失败!\n");

return FALSE;
}

pFile= pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,strObject,NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT);
if(pFile== NULL)//找不到网络地址
{
g_DebugMsg.Sprintf("找不到网络地址!\n");

sess.Close();
return FALSE;
}

pFile-> AddRequestHeaders("Content-Type: application/x-www-form-urlencoded");

// pFile-> AddRequestHeaders("Content-Type: HappiGo/Process");

// pFile-> AddRequestHeaders("Accept: */*");

if (!pFile->SendRequest(NULL,0,(LPTSTR)(LPCTSTR)strPara, strPara.GetLength()))
{
g_DebugMsg.Sprintf("SendRequest error!\n");

pFile->Close();
sess.Close();

return FALSE;
}

CString strSentence;
DWORD dwStatus;
DWORD dwBuffLen=sizeof(dwStatus);
BOOL bSuccess= pFile->QueryInfo(HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,&dwStatus,&dwBuffLen);

//if( bSuccess&& dwStatus>=200&& dwStatus<300)
if( bSuccess&& dwStatus==200)
{
strInfo.Format("dwStatus:%d\n",dwStatus);
printf("dwStatus:%d\n",dwStatus);

char buffer[2049];
memset(buffer,0,2049);

int nReadCount=0;

while((nReadCount= pFile->Read(buffer,2048))>0)
{
strContent+= buffer;
memset(buffer,0,2049);
}

//strInfo.Format("strContent:%s\n",strContent);
//g_DebugMsg.Sprintf("return Content :%s\n",strContent);
bRet=TRUE;
}
else//错误
{
if (bSuccess&& dwStatus>200 && dwStatus<300)
{
char buffer[2049];
memset(buffer,0,2049);

int nReadCount=0;

while((nReadCount= pFile->Read(buffer,2048))>0)
{
strContent+= buffer;
memset(buffer,0,2049);
}

strInfo.Format("strContent:%s\n",strContent);
g_DebugMsg.Sprintf("return Content :%s\n",strContent);
}

bRet=FALSE;
}

pFile->Close();
sess.Close();

}
catch (CInternetException *e)
{
g_DebugMsg.Sprintf("ERROR001 :error code is %ld\n",e->m_dwError);

bRet=FALSE;

}
catch (...)
{
g_DebugMsg.Sprintf("Unknown Error\n");

bRet=FALSE;
}

return bRet;
}

CPP-网络/通信:POST的更多相关文章

  1. [转]Android的网络与通信

    本文转自:http://www.cnblogs.com/qingblog/archive/2012/06/15/2550735.html 第一部分 Android网络基础   Android平台浏览器 ...

  2. socket 网络编程

    1. 基础socket库 socket.h: /** * 网络套接字库 */ #ifndef Socket_h #define Socket_h #include <stdio.h> #i ...

  3. Day8 - Python网络编程 Socket编程

    Python之路,Day8 - Socket编程进阶   本节内容: Socket语法及相关 SocketServer实现多并发 Socket语法及相关 socket概念 socket本质上就是在2台 ...

  4. HCNA之网络通信基础

    一.通信与网络 通信的概念我们并不陌生,在人类社会的起源和发展过程中,通信就直伴随着我们.般认为, 20世纪七.八十年代,人类社会已进入到信息时代,对于生活在信息时代的我们,通信的必要性和重要性更是不 ...

  5. 初学Python——Socket网络编程

    认识socket socket本质上就是在2台网络互通的电脑之间,架设一个通道,两台电脑通过这个通道来实现数据的互相传递.我们知道网络 通信 都 是基于 ip+port(端口) 方能定位到目标的具体机 ...

  6. go语言之行--网络编程、http处理流程详情

    一.简介 go语言中的网络编程主要通过net包实现,net包提供了网络I/O接口,包括HTTP.TCP/IP.UDP.域名解析和Unix域socket等.和大多数语言一样go可以使用几行代码便可以启动 ...

  7. docker进阶——数据管理与网络

    一.数据卷管理 用户在使用 Docker 的过程中,势必需要查看容器内应用产生的数据,或者 需要将容器内数据进行备份,甚至多个容器之间进行数据共享,这必然会涉及 到容器的数据管理 (1)Data Vo ...

  8. Day8-Python3基础-Socket网络编程

    目录: 1.Socket语法及相关 2.SocketServer实现多并发 Socket语法及相关 socket概念 socket本质上就是在2台网络互通的电脑之间,架设一个通道,两台电脑通过这个通道 ...

  9. Python之网络编程 Socket编程

    本节内容: Socket语法及相关 SocketServer实现多并发 Socket语法及相关 socket概念 socket本质上就是在2台网络互通的电脑之间,架设一个通道,两台电脑通过这个通道来实 ...

  10. Day8-面向对象进阶&&socket基础

    抽象类 python2中的写法 import abc class Alert(object): '''报警基类''' __metaclass__ = abc.ABCMeta @abc.abstract ...

随机推荐

  1. HTML学习笔记(二)HTML格式化

    很多标签都可以用来改变文本的外观,并为文本关联其隐藏的含义.总地来说,这些标签可以分成两类:基于内容的样式(content-based style)和物理样式(physical style). 一.基 ...

  2. LeetCode: 521 Longest Uncommon Subsequence I(easy)

    题目: anysubsequence of the other strings. A subsequence is a sequence that can be derived from one se ...

  3. 割点(Tarjan算法)

    本文可转载,转载请注明出处:www.cnblogs.com/collectionne/p/6847240.html .本文未完,如果不在博客园(cnblogs)发现此文章,请访问以上链接查看最新文章. ...

  4. 洛谷 - P1593 - 因子和 - 费马小定理

    类似的因为模数比较小的坑还有卢卡斯定理那道,也是有时候逆元会不存在,因为整除了.使用一些其他方法避免通过逆元. https://www.luogu.org/fe/problem/P1593 有坑.一定 ...

  5. IOS Carthage安装、使用

    一.Carthage的安装和使用1.安装homebrew后输入如下命令 $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercont ...

  6. 类的property特性

    目录 什么是 property特性 简单示例 property属性的两种方式 装饰器 类属性方式 property+类的封装 应用 私有属性添加getter和setter方法 使用property升级 ...

  7. Hackintosh

    条件:Mac环境(也可在Windows电脑上用虚拟机建立).两只(一只亦可)16G及以上优盘.一块64G以上SSD固态(机械)硬盘.一台待折腾的Windows电脑 1.创建安装盘: ·app stor ...

  8. C 语言实例 - 字符转 ASCII 码

    C 语言实例 - 字符转 ASCII 码 C 语言实例 C 语言实例 ASCII 定义了 个字符. 分类: 一:-.(删除键)是控制字符 二:空白字符:空格(). 制表符. 垂直制表符. 换行. 回车 ...

  9. urllib库的基本使用

    urllib库的使用 官方文档地址:https://docs.python.org/3/library/urllib.html 什么是urllib Urllib是python内置的HTTP请求库包括以 ...

  10. 关于css中父元素与子元素之间margin-top的问题

    之前在使用经常遇到下面的问题: html: <div class="top"> <div class="one">I'm the fir ...