您的位置:首页 > 理论基础 > 计算机网络

用CHttpFile实现简单的GET/POST数据【转】

2016-06-28 17:47 435 查看
一、GET 数据,下载网页,文件等,用于可下载的文件,不能用于服务端运行的程序,比如.aspx文件等,否则会返回500错误。

CString strSentence, strWriteName="1.htm";
CString strFileName="http://localhost/InDesign/" + strWriteName;

CInternetSession sess;
CHttpFile* fileGet;
try
catch(CException* e)

if(fileGet)
else
AfxMessageBox("不能找到网页文件!");

sess.Close();

二、POST 数据,比如用于提交注册信息等

CString strHttpName="http://localhost/TestReg/RegForm.aspx"; // 需要提交数据的页面
CString strFormData = "username=abc&password=123"; // 需要提交的数据

CInternetSession sess;
CHttpFile* fileGet;
CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded"); // 请求头

try
catch(CException* e)

CString strSentence, strGetSentence = "";
if(fileGet)
else
AfxMessageBox("不能找到网页文件!");

sess.Close();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: