自己按照使用http建立网络连接写的程序
//如果 Internet 会话读取或写入数据,必须创建 CInternetFile
CInternetFile* webfile=NULL; //定义一个文件对象指针
//定义网络连接Session对象
CInternetSession httpsession;
//连接到Http服务器
CHttpConnection *httpconn=httpsession.GetHttpConnection(_T("http://www.baidu.com"),0,80,NULL,NULL);
//打开Http请求
CHttpFile *httpfile=httpconn->OpenRequest(_T("GET"),_T("/index.html"));
//发送Http请求
httpfile->AddRequestHeaders(_T("Accept:*/*\r\n\r\n"));
httpfile->SendRequest(_T("Accept:*/*\r\n\r\n"));
//读取 HTTP 文件,从服务器读取字节流(bytes)
CString httpstr;
CString tmp;
while(httpfile->ReadString(tmp))
{
httpstr+=tmp;
m_Text+=httpstr;
}