赞
踩
- //有三种方法
- '方法一(只适用于MFC工程):
- //参数URL:网页地址
- //返回CString就是网页源码
- //返回的网页源码是UTF8格式,要转成ANSI等编码才能正常显示
- #include <afxinet.h>
- CString GetWebSource(CString URL)
- {
- CInternetSession Session(NULL,0);
- CString PageData;
- CString TempData;
- CHttpFile*HttpFile=(CHttpFile*)Session.OpenURL(URL);
- while(HttpFile->ReadString(TempData))
- {
- PageData+=TempData;
- }
- HttpFile->Close();
- delete HttpFile;
- Session.Close();
- //这里返回的网页源码是UTF8格式,要转成ANSI等编码才能正常显示
- return PageData;
- }
- '方法二:
- 首先引用:
- #import <msxml4.dll> named_guids
- using namespace MSXML2;
- CString resaa;
- IXMLHTTPRequestPtr httpRes;
- HRESULT hr=httpRes.CreateInstance("MSXML2.XMLHTTP");
- if(!SUCCEEDED(hr))
- {
- AfxMessageBox("无法创建XMLHTTP对象,请检查是否安装了MS XML运行库!");
- }
- LPCTSTR url="http://localhost/changjun/asxml.asp";
- httpRes->open("Get",url,false,"","");
- httpRes->sen
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。