ServerImgDownloadTask.cpp 775 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "StdAfx.h"
  2. #include "ServerImgDownloadTask.h"
  3. #include "..\EvaluationUtil\HttpClient.h"
  4. #include <afx.h>
  5. CServerImgDownloadTask::CServerImgDownloadTask(const CString &imgpath,const CString & url )
  6. {
  7. m_imgpath = imgpath;
  8. m_url = url;
  9. }
  10. CServerImgDownloadTask::~CServerImgDownloadTask(void)
  11. {
  12. }
  13. void CServerImgDownloadTask::Run()
  14. {
  15. m_result =false;
  16. bool succss =false;
  17. for (int i=0;i<5&&!succss;i++)
  18. {
  19. CHttpClient httpClient;
  20. vector<char> data;
  21. int ret =httpClient.HttpDownload(m_url,0,data);
  22. if(ret==CHttpClient::SUCCESS){
  23. CFile file;
  24. ret =file.Open(m_imgpath,CFile::OpenFlags::modeCreate|CFile::OpenFlags::modeWrite);
  25. if(ret){
  26. file.Write(data.data(),data.size());
  27. file.Close();
  28. succss =true;
  29. m_result =true;
  30. }
  31. }
  32. }
  33. }