Font
[thread]1093[/thread]

get url mit c++

Reader: 1


<< >> 4 entries, 1 page
Robby
 2003-11-25 14:12
#10823 #10823
User since
2003-08-11
409 articles
BenutzerIn
[default_avatar]
Hallo,

wie kann ich denn eine URL

z.b. www.test.de/search.php?suche=test

auslesen und in eine Textdatei oder variable speichern??
Kaum macht man es richtig - schon funktioniert es!
esskar
 2003-11-25 15:26
#10824 #10824
User since
2003-08-04
7321 articles
ModeratorIn

user image
windows?

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
BYTE* RetrieveWebData(char* url, unsigned long* size)
{
   void* pbdata = NULL;
   unsigned long cbdata = 0;
   unsigned long flags = 0;
   unsigned long toread = 1024;
   CLNTSETTINGS websettings;


   HINTERNET hsession = 0;
   HINTERNET hrequest = 0;

   GetWebClientSettings(&websettings);

   if(!(hsession = InternetOpen(HTTP_USERAGENT, INTERNET_OPEN_TYPE_PROXY, *websettings.proxy ? websettings.proxy : 0, 0, 0))) return 0;

   InternetSetOption(hsession, INTERNET_OPTION_RECEIVE_TIMEOUT, &websettings.tmo_recv, sizeof(unsigned long));
   InternetSetOption(hsession, INTERNET_OPTION_CONNECT_TIMEOUT, &websettings.tmo_conn, sizeof(unsigned long));

   flags = INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP | INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS | INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_NO_UI | INTERNET_FLAG_PASSIVE | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID;

   if(hrequest = InternetOpenUrl(hsession, url, 0, 0, flags, 0))
   {
       void* newbuffer = NULL;
       void* buffer = NULL;
       unsigned long len = 0;

       pbdata = buffer = (void*)malloc(toread + 15);

       while(InternetReadFile(hrequest, buffer, toread, &len))
       {
           cbdata += len;
           if(len != toread) break;

           newbuffer = (void*)realloc(pbdata, cbdata + toread + 15);
           pbdata = newbuffer;
           buffer = (void*)((BYTE*)pbdata+cbdata);
       }
       InternetCloseHandle(hrequest);
   }

   InternetCloseHandle(hsession);

   if(size) *size = cbdata;

   return (BYTE*)pbdata;
}

void WriteFile(char* file, BYTE* pbdata, unsigned long cbdata)
{
   FILE* pfile = NULL;
   if((pfile = _fsopen(file, "wb", _SH_DENYRW)))
   {
       fwrite(pbdata, sizeof(BYTE), cbdata, pfile);
       fclose(pfile);
   }
}

bool RetrieveWebDataToFile(char* url, char* outfile)
{
   BYTE* pbdata = 0;
   unsigned long cbdata = 0;
   bool retval = false;

   if(retval = ((pbdata = RetrieveWebData(url, &cbdata))) != NULL)
   {
       WriteFile(outfile, pbdata, cbdata);
       free(pbdata);
   }

   return retval;
}


GetWebClientSettings ist in eine funktion von mir, die optionen meines programms aus der registry liest... also zu vernachlässigen!\n\n

<!--EDIT|esskar|1069767020-->
Robby
 2003-11-25 15:35
#10825 #10825
User since
2003-08-11
409 articles
BenutzerIn
[default_avatar]
*cool*

gleich mal ausprobieren....Danke!
Kaum macht man es richtig - schon funktioniert es!
esskar
 2003-11-25 15:52
#10826 #10826
User since
2003-08-04
7321 articles
ModeratorIn

user image
muss gehen...
da beruhen viele meiner Programme ... :)
<< >> 4 entries, 1 page



View all threads created 2003-11-25 14:12.