read a remote file in a char * variable

People, how do I read a remote file in a variable Respectively, I need some function like

char *file_get_contents ( char *url )

so that i can

remote_file = file_get_contents ( "http://192.168.0.10/somefile.html" );

 Is there some straightforward way



Answer this question

read a remote file in a char * variable

  • Scott Steigerwald

    To use URLDownloadToCacheFile:

  • Filiberto Selvas MSFT

    OShah,

    Thanks.

    However, I need to download the same file for many times. At the moment the function downloads it only once... What could be the problem


  • Rover

    Note that the file may reside in a different share other than the root folder, which may be hidden (eg. under the C$\inetpub folder or a www$). Make sure you check those alternatives. You may want to check with the administrator of the web server to be sure. If you can get the LAN filename of the file, then you can just use the standard C [ ++ ] calls to open the file.

    However, I assume that you want to access a sophisticated web server (eg. IIS, Apache, ...), and you want to capture the output after it is processed by the web server. In that case, you will have to use HTTP.

    Fortunately, internet explorer provides some very simple APIs that allow you to access such a resource. The APIs are:

    • URLDownloadToFile (downloads to a file of your choice)
    • URLDownloadToCacheFile (downloads to Temporary Internet Files. Use if you don't know where to put to your file)
    • URLOpenBlockingStream (downloads to an IStream)
    • URLOpenPullStream (downloads asynchronously to your IBindStatusCallback)

    I suppose you could also connect the network using winsock, but then you would have to reimplement HTTP all by yourself (HTTP API may help, but it's only available in recent service packs).



  • Jmp

    OShah,

    Is there some example of the APIs you have named I have been looking for the examples, but I couldn't find them. I'm not very familiar with msvc.

    I have also tried to use the curl library, but the linker throws out errors like "main.obj : error LNK2001: unresolved external symbol __imp__curl_easy_cleanup". The manual on curl says:

    "When building an application that uses the static libcurl library, you must
    add -DCURL_STATICLIB to your CFLAGS. Otherwise the linker will look for
    dynamic import symbols."

    The question is: how to edit CFLAGS in msvc9


  • skiersdelight

    Before trying to do this through HTTP, are you able to do this by going through the LAN

    filename = "\\\\192.168.0.10\\www\\somefile.html"
    // this will open somefile.html using NetBIOS and the Windows Network,
    // like how a mapped network drive works.



  • Coyote13

    I think it's an optimization made by Internet Explorer. Internet Explorer only downloads a file if it has changed on the server, otherwise it recycles the file from the cache (btw, that's why you sometimes need to press Ctrl-F5 to get a fresh copy of a file that has changed).

    The API is dictated by the setting in Control Panel -> Internet Options -> General -> Temporary Files -> Settings -> Check for newer versions of stored pages.

    What you can do is delete the file once you have downloaded it. That should remove it from cache.

    Did you get libcurl working



  • cYruZ

    OShah,

    Thanks. However, the file can only be accessed via HTTP.


  • read a remote file in a char * variable