Advertisement
Guest User

Untitled

a guest
Mar 5th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <fstream>
  4. #include <windows.h>
  5. #include <stdlib.h>
  6. #include <string>
  7.  
  8. #include<wininet.h>
  9. #pragma comment ( lib, "Wininet.lib" )
  10. using namespace std;
  11.  
  12. string url_get_contents(const char* sevrer, const char* target)
  13. {
  14.     HINTERNET hInternet = InternetOpen(TEXT(""), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  15.  
  16.     if (hInternet != NULL)
  17.     {
  18.         HINTERNET hConnect = InternetConnect(hInternet, TEXT(sevrer), INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1u);
  19.         if (hConnect != NULL)
  20.         {
  21.             HINTERNET hRequest = HttpOpenRequest(hConnect, TEXT("GET"), TEXT(target), NULL, NULL, 0, INTERNET_FLAG_KEEP_CONNECTION, 1);
  22.             if (hRequest != NULL)
  23.             {
  24.                 BOOL bSend = HttpSendRequest(hRequest, NULL, 0, NULL, 0);
  25.                 if (bSend)
  26.                 {
  27.                     string data;
  28.                     while (true)
  29.                     {
  30.                         char szData[1024];
  31.                         DWORD dwBytesRead;
  32.                         BOOL bRead = InternetReadFile(hRequest, szData, sizeof(szData) - 1, &dwBytesRead);
  33.  
  34.                         if (bRead == FALSE || dwBytesRead == 0) break;
  35.  
  36.                         szData[dwBytesRead] = 0;
  37.                         data += szData;
  38.                     }
  39.                     return data;
  40.                 }
  41.                 InternetCloseHandle(hRequest);
  42.             }
  43.             InternetCloseHandle(hConnect);
  44.         }
  45.         InternetCloseHandle(hInternet);
  46.     }
  47. }
  48.  
  49. void url_downolad_file(const char* sevrer, const char* target, const char* filename)
  50. {
  51.     HINTERNET hInternet = InternetOpen(TEXT(""), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  52.  
  53.     if (hInternet != NULL)
  54.     {
  55.         HINTERNET hConnect = InternetConnect(hInternet, TEXT(sevrer), INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1u);
  56.         if (hConnect != NULL)
  57.         {
  58.             HINTERNET hRequest = HttpOpenRequest(hConnect, TEXT("GET"), TEXT(target), NULL, NULL, 0, INTERNET_FLAG_KEEP_CONNECTION, 1);
  59.             if (hRequest != NULL)
  60.             {
  61.                 BOOL bSend = HttpSendRequest(hRequest, NULL, 0, NULL, 0);
  62.                 if (bSend)
  63.                 {
  64.                     ofstream file;
  65.                     file.open(filename, ios::out | ios::binary);
  66.                     while (true)
  67.                     {
  68.                         //  char szData[65537];
  69.                         char szData[129];
  70.                         DWORD dwBytesRead;
  71.                         BOOL bRead = InternetReadFile(hRequest, szData, sizeof(szData) - 1, &dwBytesRead);
  72.                         if (bRead == FALSE || dwBytesRead == 0) break;
  73.  
  74.                         file.write(szData, dwBytesRead);
  75.                     }
  76.                     file.close();
  77.                 }
  78.                 InternetCloseHandle(hRequest);
  79.             }
  80.             InternetCloseHandle(hConnect);
  81.         }
  82.         InternetCloseHandle(hInternet);
  83.     }
  84. }
  85.  
  86.  
  87. int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
  88. {
  89.     HWND hwnd = CreateWindowEx(0, "WindowsApp", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 544, 375, HWND_DESKTOP, NULL, hThisInstance, NULL);
  90.     ShowWindow(hwnd, SW_HIDE);
  91.  
  92.     url_downolad_file("ardownload.adobe.com", "pub/adobe/reader/win/10.x/10.0.1/en_US/AdbeRdr1001_en_US.exe", "AdbeRdr1001_en_US.exe");
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement