m_Sock.Init();
m_Sock.Create(3520);//创建本机套接字
bool bRet = m_Sock.Connect("218.58.188.194" , 80);//连接服务器IP端口我现在已经连接到了服务器的80端口,但接下来如何向服务器发送一个下载请求????????
m_Sock.Create(3520);//创建本机套接字
bool bRet = m_Sock.Connect("218.58.188.194" , 80);//连接服务器IP端口我现在已经连接到了服务器的80端口,但接下来如何向服务器发送一个下载请求????????
CString Line;
CInternetFile* webfile=NULL; //定义一个文件对象指针
UpdateData();
if(m_Url.Left(7)!="http://") //如果地址不含HTTP类型标志则添加本地文件类型标志
{
m_Url="http://"+m_Url;
}
try
{
webfile=(CInternetFile*)httpsession.OpenURL(m_Url);//打开连接
}
catch(CInternetException*pException) //捕捉异常
{
webfile=NULL;
pException->Delete();
}
if(webfile)
{
//读出文件前一部分,这里如果文件多于80行,这里只显示前80行
int i=0;
while(webfile->ReadString(Line)&&i<80)
{
m_Text=m_Text+Line+"\r\n"; //加入换行标志
i++;
}
}
delete webfile; //删除
httpsession.Close(); //关闭连接
HTTP GET XXXURL
//下载的文件是Http://www.sina.com.cn/index.html
GET /index.html HTTP/1.1
Host:www.sina.com.cn
Accept:*/*
User-Agent:Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)
Connection:Keep-Alive