Like Tree12Likes

urgent help needed with c++ webpage read data

This is a discussion on urgent help needed with c++ webpage read data within the C++ Programming forums, part of the General Programming Boards category; hi I am new to c++ web development for windows. I need to connect to webpage URL from c++ and ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    162

    Thumbs up urgent help needed with c++ webpage read data

    hi


    I am new to c++ web development for windows. I need to connect to webpage URL from c++ and fetch some data from website line by line. how this can be achieved? I am new to windows sockets also. Do I need winInet or winHTTP apis? any code is available for understanding basic work flow?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,893
    Why exactly do you want to do web development in C++?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    162
    Its not web development...actually want to read some data from web pages in c++..any idea how to do it?

  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    162
    The URL it attempts to read will look like this:Video Games, Game Reviews & News - G4tv.com

  5. #5
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Use libcurl to fetch the page into a std::string and parse it from there?

    Here is a function you can use as a callback to curl that will put the contents in a string. This is blatantly stolen from a stackoverflow thread, but i've used it a few times and it works great.

    Code:
    static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
    {
        ((std::string*)userp)->append((char*)contents, size * nmemb);
        return size * nmemb;
    }
    You would call it like this:

    Code:
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
    Where buffer is your std::string.
    The rest is up to you.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  6. #6
    Registered User
    Join Date
    Nov 2008
    Posts
    162
    I am not familair with libcurl...is it some kind of wrapper apis?
    I was seeing if winsock coudl be used here? Create a socket and give it the server information that you wish to connect to (ip, port number etc) and then simply connect to the server. Once connected you send data to it using the http protocol and read the response back and store it in a buffer. Then parse the buffer. is it correct?any sampel code would help better.

  7. #7
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    libcurl does all the work for you, simply google it. You could do it using sockets directly but that would be much more work. Also, unlike winsocks, libcurl is portable.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  8. #8
    Registered User
    Join Date
    Nov 2008
    Posts
    162
    Quote Originally Posted by Neo1 View Post
    libcurl does all the work for you, simply google it. You could do it using sockets directly but that would be much more work. Also, unlike winsocks, libcurl is portable.
    any libcurl c++ demo code available for testing functionality?

  9. #9
    Registered User
    Join Date
    Nov 2008
    Posts
    162
    any native solution readily available instead of using this third party library like libcurl?

  10. #10
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by leo2008 View Post
    any libcurl c++ demo code available for testing functionality?
    libcurl - source code examples

    This would have taken you no more than 10 seconds to find if you bothered to just Google libcurl.

    Libcurl has a C API, but there are bindings for C++ as well. Personally i just use the C API.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  11. #11
    Registered User
    Join Date
    Oct 2006
    Posts
    2,493
    this really seems like a "give me teh codez" kind of thread.
    rags_to_riches and Salem like this.
    Code:
    namespace life
    {
        const bool change = true;
    }

  12. #12
    Registered User
    Join Date
    Nov 2008
    Posts
    162

    Thumbs up

    Quote Originally Posted by Elkvis View Post
    this really seems like a "give me teh codez" kind of thread.
    I need to connect to webpage URL asynchronously. How can this be done? please help.

  13. #13
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by leo2008 View Post
    I need to connect to webpage URL asynchronously. How can this be done? please help.
    Well, i'm out.

    http://i.imgur.com/J7BMq.gif
    Elkvis and Salem like this.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  14. #14
    Registered User
    Join Date
    Nov 2008
    Posts
    162
    Is there any libcurl code for non-blocking HTTP client interfaces.???

  15. #15
    Registered User
    Join Date
    Nov 2008
    Posts
    162
    can libcurl be used for windows?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Urgent Help needed!
    By Superstar90 in forum C++ Programming
    Replies: 3
    Last Post: 11-10-2009, 03:21 PM
  2. Extracting data from a webpage
    By h3ro in forum Tech Board
    Replies: 6
    Last Post: 09-25-2009, 05:12 AM
  3. Read Webpage
    By Loic in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2008, 10:23 PM
  4. Replies: 1
    Last Post: 12-01-2002, 12:24 PM
  5. posting data to webpage...
    By Turek in forum C++ Programming
    Replies: 2
    Last Post: 07-29-2002, 11:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21