Advertisement
ipsBruno

(C++) url_get_contents

Nov 4th, 2012
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1.  /*
  2.  *  Copyright (c) 2012 [iPs]TeaM
  3.  *  Bruno da Silva (email@brunodasilva.com)
  4.  *  Função url_get_contents em c++
  5.  *
  6.  * www.brunodasilva.com
  7.  * www.ips-team.forumeiros.com
  8. */    
  9.  
  10.  
  11. #include <urlmon.h>
  12. #pragma comment(lib, "urlmon.lib")
  13.  
  14. //  file_get_contents :)
  15.  
  16. char * url_get_contents(TCHAR * url) {
  17.  
  18.     char * retorno;
  19.  
  20.     retorno = (char *) malloc(256 * sizeof(char));
  21.  
  22.     if(S_OK == URLDownloadToCacheFileA(NULL,  url, retorno, 255, 0, NULL)) {
  23.  
  24.         char
  25.             tmpString[100]
  26.         ;
  27.  
  28.         FILE * fp = fopen(retorno, "r");
  29.  
  30.         retorno[0] = 0;
  31.  
  32.         while (fgets (tmpString, 100, fp) != NULL) {
  33.             strcat(retorno, tmpString);
  34.         }
  35.  
  36.         fclose(fp);
  37.  
  38.         return retorno;
  39.     }
  40.  
  41.     return NULL;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement