1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C++ Download from URL

Discussion in 'C, C++, C#' started by DMSEsquire, Dec 13, 2010.

  1. DMSEsquire

    DMSEsquire BANNED BANNED

    Joined:
    Dec 4, 2010
    Messages:
    235
    Likes Received:
    69
    Hey guys, I'm a C++ programmer, so I know how simple this program is. However, I'm lazy and don't feel like researching/coding today. Does anyone want to provide the C++ code to get the HTML from a URL and output it to a text file? Just curious to see if anyone has that lying around and would like to share.
     
  2. heiska

    heiska Junior Member

    Joined:
    Dec 5, 2008
    Messages:
    138
    Likes Received:
    169
    Ugh, nvm. I'll edit when I actually have something...
     
    Last edited: Dec 14, 2010
  3. MaDeuce

    MaDeuce Newbie

    Joined:
    Oct 24, 2008
    Messages:
    45
    Likes Received:
    16
    Location:
    Austin, TX
    Reference: curl.haxx.se

    Code:
    #include <stdio.h>
    #include <curl/curl.h>
     
    int main(void)
    
    {
      CURL *curl;
      CURLcode res;
     
      curl = curl_easy_init();
      if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
        res = curl_easy_perform(curl);
     
        /* always cleanup */ 
        curl_easy_cleanup(curl);
      }
      return 0;
    }
    
     
    • Thanks Thanks x 1
  4. DMSEsquire

    DMSEsquire BANNED BANNED

    Joined:
    Dec 4, 2010
    Messages:
    235
    Likes Received:
    69
    Awesome, much appreciated. Any help on installing the curl/libcurl libraries?
     
  5. MaDeuce

    MaDeuce Newbie

    Joined:
    Oct 24, 2008
    Messages:
    45
    Likes Received:
    16
    Location:
    Austin, TX
    What's your specific problem? It's been at least a year since I did an install, but I don't recall any problems. At least nothing major. I installed the binary version and did not download/build from source.

    OS?
    Did you install binary or source?
    Did the install produce errors?
    Or did the install go OK and you can't link?
    Or can you link OK and it just doesn't work?
     
  6. DMSEsquire

    DMSEsquire BANNED BANNED

    Joined:
    Dec 4, 2010
    Messages:
    235
    Likes Received:
    69
    I'm on Windows 7, using Dev to compile.

    I put the curl folder into Dev's include, as per instructions, and yet when I try to run the code you have there Dev is returning linker error. It's unable to find any of the files (I'm using libcurl, btw).
     
  7. MaDeuce

    MaDeuce Newbie

    Joined:
    Oct 24, 2008
    Messages:
    45
    Likes Received:
    16
    Location:
    Austin, TX
    Well, seeing as I am a Unix/Linux guy, I probably won't be of much help to you here. However, there are some things that are pretty much universal, regardless of OS.

    Off the top of my head, I can thing of a couple of generic problems. If you are getting errors relating to include files, specifically 'unable to find' or something similar, either of two things could be happening. The first is that the include files are installed in the wrong location. However, if you used some sort of installer, this is probably not your problem. Another problem could be that the includes are in the correct location, but the compiler doesn't know where they are. That is typically done via a command line arg, '-I', which is followed by the location of a directory that contains include files. This option can be repeated, if necessary, for additional include directories.

    The other generic problem would be that the includes are OK, but that, after compiling, the linker can find all the necessary libraries. As with -I, the -L command line arg tells the linker where to look for libraries.

    It is possible that either one, or both, of -I and -L are not being set correctly to reflect Curl's install location.

    While I've never had to use it, I noted that there is a page on the Curl web site, which discusses a tool that can be used to determine what the correct -I and -L flags are to compile and link with Curl. Check out http://curl.haxx.se/libcurl/using/

    Another configuration related page: http://curl.haxx.se/libcurl/using/curl-config.html

    If it's not one of these, I'm afraid that you are on your own. Or at least, I can't offer additional help. Window's ain't my cup of tea.

    --Ma
     
    • Thanks Thanks x 1