Advertisement
jimmybbb

HttpSendRequest

Nov 25th, 2011
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1.  
  2. int doHttpPost(char *szDomain, char *szPage, char *szPost)
  3. {
  4.     int iReturn = 1;
  5.     HINTERNET hSession = NULL;
  6.     HINTERNET hConnect = NULL;
  7.     HINTERNET hRequest = NULL;
  8.  
  9.     static TCHAR hdrs[] = "Content-Type: application/x-www-form-urlencoded";
  10.     const char *accept[2]={"*/*", NULL};
  11.     TCHAR *frmdata = szPost;
  12.  
  13.     hSession = InternetOpen("AGENT", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  14.     if(hSession)
  15.     {
  16.         hConnect = InternetConnect(hSession, szDomain, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
  17.         if(hConnect)
  18.         {
  19.             hRequest = HttpOpenRequest(hConnect, "POST", szPage, NULL, NULL, accept, INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_NO_UI | INTERNET_FLAG_RELOAD, 0);
  20.             if(hRequest)
  21.             {
  22.                 if(HttpSendRequest(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata)))
  23.                     iReturn = 0;
  24.                 else
  25.                     iReturn = 5;
  26.             }
  27.             else    //HttpOpenRequest
  28.                 iReturn = 3;
  29.         }
  30.         else    //InternetConnect
  31.             iReturn = 2;
  32.     }
  33.     else  //InternetOpen
  34.         iReturn = 1;
  35.  
  36.     //Cleanup
  37.     InternetCloseHandle(hSession);
  38.     InternetCloseHandle(hConnect);
  39.     InternetCloseHandle(hRequest);
  40.  
  41.     return iReturn;
  42. }
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement