抓取网页内容的实例我就是对输入的URL确定按钮添加函数,为什么出现了这样的错误呢,不知从哪里下手了
我的代码是
void CGetHttpStrDlg::OnOK()
{
// TODO: Add extra validation here
//获取输入的URL
CString strUrl;
GetDlgItemText(IDC_EDT_URL,strUrl);
//创建Internet会话
CInternetSession session(NULL,0);
CHttpFile*file=NULL;
CString strContent;
//打开URL
try
{
file=(CHttpFile*)session.OpenURL(strUrl);
}
catch(CInternetException*pException)
{
pException->ReportError();
pException->Delete();
return;
}
//循环读取内容
CString strTemp;
while(file->ReadString(strTemp))
{
strContent+=strTemp;
}
//释放资源
file->Close();
delete file;
session.Close();
SetDlgItemText(IDC_EDT_CONTENT,strContent);
// CDialog::OnOK();
}
它提示的错误时
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(179) :errorC2065: 'CInternetSession' : undeclared identifier
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(179) : error C2146: syntax error : missing ';' before identifier 'session'
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(179) : error C2065: 'session' : undeclared identifier
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(180) : error C2065: 'CHttpFile' : undeclared identifier
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(180) : error C2065: 'file' : undeclared identifier
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(180) : error C2106: '=' : left operand must be l-value
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(185) : error C2059: syntax error : ')'
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(187) : error C2061: syntax error : identifier 'CInternetException'
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(187) : error C2310: catch handlers must specify one type
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(189) : error C2065: 'pException' : undeclared identifier
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(189) : error C2227: left of '->ReportError' must point to class/struct/union
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(190) : error C2227: left of '->Delete' must point to class/struct/union
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(194) : error C2317: 'try' block starting on line '184' has no catch handlers
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(195) : error C2227: left of '->ReadString' must point to class/struct/union
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(195) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.GetHttpStr.exe - 15 error(s), 0 warning(s)
URL
我的代码是
void CGetHttpStrDlg::OnOK()
{
// TODO: Add extra validation here
//获取输入的URL
CString strUrl;
GetDlgItemText(IDC_EDT_URL,strUrl);
//创建Internet会话
CInternetSession session(NULL,0);
CHttpFile*file=NULL;
CString strContent;
//打开URL
try
{
file=(CHttpFile*)session.OpenURL(strUrl);
}
catch(CInternetException*pException)
{
pException->ReportError();
pException->Delete();
return;
}
//循环读取内容
CString strTemp;
while(file->ReadString(strTemp))
{
strContent+=strTemp;
}
//释放资源
file->Close();
delete file;
session.Close();
SetDlgItemText(IDC_EDT_CONTENT,strContent);
// CDialog::OnOK();
}
它提示的错误时
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(179) :errorC2065: 'CInternetSession' : undeclared identifier
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(179) : error C2146: syntax error : missing ';' before identifier 'session'
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(179) : error C2065: 'session' : undeclared identifier
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(180) : error C2065: 'CHttpFile' : undeclared identifier
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(180) : error C2065: 'file' : undeclared identifier
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(180) : error C2106: '=' : left operand must be l-value
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(185) : error C2059: syntax error : ')'
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(187) : error C2061: syntax error : identifier 'CInternetException'
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(187) : error C2310: catch handlers must specify one type
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(189) : error C2065: 'pException' : undeclared identifier
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(189) : error C2227: left of '->ReportError' must point to class/struct/union
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(190) : error C2227: left of '->Delete' must point to class/struct/union
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(194) : error C2317: 'try' block starting on line '184' has no catch handlers
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(195) : error C2227: left of '->ReadString' must point to class/struct/union
D:\全部\网络开发篇章\GetHttpStr\GetHttpStrDlg.cpp(195) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.GetHttpStr.exe - 15 error(s), 0 warning(s)
URL
解决方案 »
- 远程注入一个DLL到记事本程序。怎么和这个DLL通信和数据传输呢?
- 请教树处理的问题,大家帮帮我,急等中...
- 怎么实现气泡式的文本提示框??在线等,急!!!
- 如何用WinInet模拟表单提交操作,需要处理target
- 请问下面的通信模型如何做比较好?
- typedef HRESULT(_stdcall *DLLGETCLASSOBJECT) (REFCLSID rclsid,REFIID riid,LPVOID *ppv);是什么意思
- 请大家全面的解释一下THROW关键字的用法
- 高手门请看这一个程序(急)
- 问题有点难喔!
- 怎样获得windows系统以安装的所有字体
- opengl es纹理如何动态更新问题
- 绘图软件序列化保存的如何去实现
与添加头文件有何区别
#include <afxinet.h>
Header: afxinet.h