Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <fstream>
- #include <iostream>
- #include <Windows.h>
- #include <WinInet.h>
- #pragma warning(disable : 4996)
- using namespace std;
- int main()
- {
- char CurDir [MAX_PATH];
- GetCurrentDirectory(sizeof(CurDir), CurDir);
- char* urlChar = new char[MAX_PATH];
- std::cin >> urlChar;
- string url(urlChar);
- int i=0,j=0;
- std::string fileName= '[' + (string)CurDir + ']';
- fileName += &url[url.find('/') + 1];//+1 для / вместо // в названии файла
- fileName.erase(fileName.find_last_of('/'));
- fileName += ".txt";
- char* writable = new char[fileName.size() + 1];
- std::copy(fileName.begin(), fileName.end(), writable);
- writable[fileName.size()] = '\0';
- strcat(CurDir, writable);
- std::cout << CurDir;
- HINTERNET hSession, hURL;
- char* Buffer = new char[1024];
- DWORD BufferLen, BytesWritten;
- HANDLE FileHandle;
- //"C:\\Users\\augus\\Desktop\\C++\\getFileHTTP\\getFileHTTP\\tx1t.txt"
- hSession = InternetOpenA(NULL, 0, NULL, NULL, 0);
- hURL = InternetOpenUrlA(hSession, urlChar, NULL, 0, 0, 0);
- FileHandle = CreateFileA("C:\\Users\\augus\\Desktop\\C++\\getFileHTTP\\getFileHTTP\\tx1t.txt", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
- BytesWritten = 0;
- do
- {
- InternetReadFile(hURL, Buffer, 1024, &BufferLen);
- WriteFile(FileHandle, Buffer, BufferLen, &BytesWritten, NULL);
- } while (BufferLen != 0);
- CloseHandle(FileHandle);
- InternetCloseHandle(hURL);
- InternetCloseHandle(hSession);
- ShellExecuteA(0, "open", "C:\\Users\\augus\\Desktop\\C++\\getFileHTTP\\getFileHTTP\\tx1t.txt", NULL, NULL, 1);
- cout << "\n\nOperation complete!";
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement