MFC下http连接网络(get方法)
来源:互联网 发布:windows nt 6.2 编辑:程序博客网 时间:2024/05/16 07:31
MFC下http连接网络
1. 初始化
#include"afxsock.h"
BOOLCHttpClinetDlg::OnInitDialog()
{
// TODO: Add extra initialization here
if(AfxSocketInit(NULL)==FALSE)
{
AfxMessageBox("Socket InitError");
}
return TRUE; // return TRUE unless you set the focus to a control
}
2. 连接网站,获取信息
voidCHttpClinetDlg::OnGet()
{
// TODO: Add your control notificationhandler code here
UpdateData(TRUE);
CInternetSession mySession(NULL,0);
CHttpFile* myHttpFile=NULL;
Cstring m_URL = “163.com”;
m_infor="link net ::"+m_URL+"/r/n";
UpdateData(false);
CString myData;
myHttpFile=(CHttpFile*)mySession.OpenURL(m_URL);
Cstring temp;
while(myHttpFile->ReadString(myData))
{
temp.Format("realLen =%d", myData.GetLength());
if (myData.GetLength())
{
MyWriteFile((BYTE*)myData.GetBuffer(myData.GetLength()),myData.GetLength());
myData.ReleaseBuffer();
}
m_infor=m_infor+"/r/n";
m_infor+=myData;
}
myHttpFile->Close();
mySession.Close();
UpdateData(false);
}
BOOLCHttpClinetDlg::MyWriteFile(BYTE *buffer, int len)
{
CFile file;
CFileException e;
CString path="";
GetModuleFileName(NULL,path.GetBuffer(MAX_PATH),MAX_PATH);
path.ReleaseBuffer();
path = path.Left(path.ReverseFind('//'));
path += "//";
path += "SaveData.txt";
if( !file.Open( path, CFile::modeCreate |CFile::modeNoTruncate | CFile::modeWrite, &e ) )
{
//´íÎó
AfxMessageBox(_T("MyWriteFileerror::"));
return FALSE;
}
file.SeekToEnd();
file.Write(buffer,len);
file.Close();
return TRUE;
}
3. 结束
- MFC下http连接网络(get方法)
- 【网络】HTTP 方法:GET 对比 POST
- java网络通信(一)使用http的get方法进行网络通信
- NameValuePair(网络http连接)
- Android之网络----使用HttpClient发送HTTP请求(通过get方法获取数据)
- 【网络】HTTP中GET和POST方法的区别
- Android 网络交互(一) HTTP post和get方法区别
- 使用Http的Get方法读取网络数据
- Qt HTTP网络相关GET,POST(HTTP 模拟POST 表单(multipartform)最简单和正式的方法)
- MFC下的网络编程(1)CAsyncSocket进行无连接(UDP)通信
- http请求方法(GET、POST)
- HTTP请求接口方法(POST/GET)
- HTTP Get 方法
- Http方法 GET/POST
- http:get&post方法
- HTTP 的get方法
- Qt5 HTTP GET方法
- http的get方法
- file system
- magento--------------输出content前字符过滤处理,现在字母个数处理
- 华为U8150(IDEOS)手机USB驱动安装
- mvvm---如何在xaml里,把多个参数传入到command
- 三种遍历文件夹方法比较(PERL)
- MFC下http连接网络(get方法)
- VisualVM
- 内存溢出与内存泄露的区别
- 热门话题:使用WCF实现SOA面向服务编程(三)—— 使用AJAX+WCF实现页面开发
- Flex性能优化常用手法总结
- IE6、IE7、IE8的CSS、JS兼容
- 软件开发方法需要理论
- PCM: flash killer or flash road kill?
- How to make SD Card world wide writable