http://blog.csdn.net/gnixuyil/article/details/7688439
获取网络图片
- CString URL="http://www.google.com.hk/images/srpr/logo3w.png"
-
- CInternetSession session;
- CHttpFile *httpFile = (CHttpFile *)session.OpenURL(URL);
- CStdioFile imgFile;
- char buff[1024];
-
- imgFile.Open("图片名字.png", CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);
-
- DWORD dwStatusCode;
- httpFile->QueryInfoStatusCode(dwStatusCode);
-
- if(dwStatusCode == HTTP_STATUS_OK) {
- int size=0;
- do {
- size = httpFile->Read(buff,1024);
- imgFile.Write(buff,size);
- }while(size > 0);
- }
-
- httpFile->Close();
- session.Close();
获取URL的html
- CInternetSession session;
- CHttpFile *httpFile = (CHttpFile *)session.OpenURL(m_URL);
-
- DWORD dwStatusCode;
- httpFile->QueryInfoStatusCode(dwStatusCode);
-
- CString getdata=_T("");
-
- if(dwStatusCode == HTTP_STATUS_OK) {
- CString line_data=_T("");
- while(httpFile->ReadString(line_data)) {
- getdata += line_data;
- }
- getdata.TrimRight();
- }
-
- httpFile->Close();
- session.Close();
-
-
- strCoding cfm;
-
- string temp = (LPCSTR)getdata.GetBuffer();
- string output;
- cfm.UTF_8ToGB2312(output,(char *)temp.data(),strlen(temp.data()));
-
- temp = output;
- DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, temp.c_str(), -1, NULL, 0);
- wchar_t *pwText;
- pwText = new wchar_t[dwNum];
- MultiByteToWideChar (CP_ACP, 0, temp.c_str(), -1, pwText, dwNum);
-
- m_data = pwText;
- delete []pwText;
编码转换类: http://blog.csdn.net/gnixuyil/article/details/7688469
C++ 获取URL图片、html文件,CInternetSession 【转】
原文:http://www.cnblogs.com/mazhenyu/p/5946203.html