Advertisement
anuisud1

Untitled

Jul 20th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <string>
  3. #include <WinInet.h>
  4. #pragma comment(lib,"ws2_32.lib")
  5. #pragma comment(lib, "wininet.lib")
  6.  
  7.  
  8. using namespace std;
  9.  
  10. string replaceAll(string subject, const string& search,
  11.     const string& replace) {
  12.     size_t pos = 0;
  13.     while ((pos = subject.find(search, pos)) != string::npos) {
  14.         subject.replace(pos, search.length(), replace);
  15.         pos += replace.length();
  16.     }
  17.     return subject;
  18. }
  19.  
  20. string DownloadURL(string URL) {
  21.     HINTERNET interwebs = InternetOpenA("Mozilla/5.0", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, NULL);
  22.     HINTERNET urlFile;
  23.     string rtn;
  24.     if (interwebs) {
  25.         urlFile = InternetOpenUrlA(interwebs, URL.c_str(), NULL, NULL, NULL, NULL);
  26.         if (urlFile) {
  27.             char buffer[2000];
  28.             DWORD bytesRead;
  29.             do {
  30.                 InternetReadFile(urlFile, buffer, 2000, &bytesRead);
  31.                 rtn.append(buffer, bytesRead);
  32.                 memset(buffer, 0, 2000);
  33.             } while (bytesRead);
  34.             InternetCloseHandle(interwebs);
  35.             InternetCloseHandle(urlFile);
  36.             string p = replaceAll(rtn, "|n", "\r\n");
  37.             return p;
  38.         }
  39.     }
  40.     InternetCloseHandle(interwebs);
  41.     string p = replaceAll(rtn, "|n", "\r\n");
  42.     return p;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement