Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1.  
  2. #include <string>
  3. #include <fstream>
  4. #include <iostream>
  5. #include <Windows.h>
  6. #include <WinInet.h>
  7.  
  8. #pragma warning(disable : 4996)
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14. char CurDir [MAX_PATH];
  15. GetCurrentDirectory(sizeof(CurDir), CurDir);
  16. char* urlChar = new char[MAX_PATH];
  17. std::cin >> urlChar;
  18. string url(urlChar);
  19. int i=0,j=0;
  20. std::string fileName= '[' + (string)CurDir + ']';
  21. fileName += &url[url.find('/') + 1];//+1 для / вместо // в названии файла
  22. fileName.erase(fileName.find_last_of('/'));
  23. fileName += ".txt";
  24. char* writable = new char[fileName.size() + 1];
  25. std::copy(fileName.begin(), fileName.end(), writable);
  26. writable[fileName.size()] = '\0';
  27. strcat(CurDir, writable);
  28. std::cout << CurDir;
  29. HINTERNET hSession, hURL;
  30. char* Buffer = new char[1024];
  31. DWORD BufferLen, BytesWritten;
  32. HANDLE FileHandle;
  33. //"C:\\Users\\augus\\Desktop\\C++\\getFileHTTP\\getFileHTTP\\tx1t.txt"
  34. hSession = InternetOpenA(NULL, 0, NULL, NULL, 0);
  35. hURL = InternetOpenUrlA(hSession, urlChar, NULL, 0, 0, 0);
  36. FileHandle = CreateFileA("C:\\Users\\augus\\Desktop\\C++\\getFileHTTP\\getFileHTTP\\tx1t.txt", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
  37. BytesWritten = 0;
  38. do
  39. {
  40. InternetReadFile(hURL, Buffer, 1024, &BufferLen);
  41. WriteFile(FileHandle, Buffer, BufferLen, &BytesWritten, NULL);
  42. } while (BufferLen != 0);
  43. CloseHandle(FileHandle);
  44.  
  45. InternetCloseHandle(hURL);
  46. InternetCloseHandle(hSession);
  47.  
  48. ShellExecuteA(0, "open", "C:\\Users\\augus\\Desktop\\C++\\getFileHTTP\\getFileHTTP\\tx1t.txt", NULL, NULL, 1);
  49.  
  50. cout << "\n\nOperation complete!";
  51. system("PAUSE");
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement