CString gethttpfiledata (CString strurl) {cinternetsession Session (_t ("Internet Explorer"),0); CHttpFile*phttpfile =NULL; CString strdata; CString Strclip; Phttpfile= (chttpfile*) Session.openurl (strURL); while(phttpfile->ReadString (Strclip)) { Char*pstr = (Char*) Strclip.getbuffer (Strclip.getlength ());//gets the original string of the Str object intNbuffersize = MultiByteToWideChar (Cp_utf8,0, PSTR,-1Null0);//how much to get the desired cachewchar_t *pbuffer = (wchar_t*)malloc(Nbuffersize *sizeof(wchar_t));//Request Cache SpaceMultiByteToWideChar (Cp_utf8,0, PSTR,-1, Pbuffer, nbuffersize*sizeof(wchar_t));//transcoding//MessageBoxW (NULL, pbuffer, L "Text", MB_OK);//ShowStrclip.format (_t ("%s"), pbuffer); //AfxMessageBox (strclip); Free(pbuffer);//releasing the cacheStrdata + =Strclip; Strdata+ = _t ("\ n"); } returnstrdata;}voidCwumadlg::onbnclickedbutton1 () {//TODO: Add control notification handler code hereCString csHtml; //Cshtml=utf8tounicode (Gethttpfiledata (_t ("http://www.baidu.com")));Cshtml=gethttpfiledata (_t ("http://www.taobao.com")); //AfxMessageBox (csHtml);CString pszFileName = _t ("d://myfile.htm"); CFile MyFile; CFileException fileexception; CFile CF; if(cf. Open (pszFileName, Cfile::modecreate |cfile::modewrite)) { intLen =cshtml.getlength (); Cf. Write (Cshtml.getbuffer (len), Len); Cf. Close (); Cshtml.releasebuffer (); AfxMessageBox (_t ("saved successfully")); }}
Read the contents of the Web page save to File