MFC框架实现,UNICODE字符集。
void Filesize()
{
//初始化数据
CString cstrSize;
CString cstrURL(_T("http://www.baidu.com/"));
CHttpFile * chFile = NULL;
CInternetSession ciSession(NULL, 0);
//获得文件大小
chFile = (CHttpFile *)ciSession.OpenURL(cstrURL);
chFile->QueryInfo(HTTP_QUERY_STATUS_CODE, cstrSize);
if(cstrSize == "200") {
chFile->QueryInfo(HTTP_QUERY_CONTENT_LENGTH, cstrSize);
}
//对获得的文件大小进行一些处理
CW2A charstr((LPCTSTR)cstrSize);
int fileSizeBytes = atoi(charstr);
CString showup;
showup.Format(_T("FILE SIZE IS %d B"), fileSizeBytes);
MessageBox(NULL, showup, _T("FILE SIZE"), MB_OK);
return;
}