Thread: urgent help needed with c++ webpage read data

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

    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
    28,413
    Why exactly do you want to do web development in C++?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    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
    222
    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
    222
    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
    222
    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
    222
    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
    3,445
    this really seems like a "give me teh codez" kind of thread.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

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

    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
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

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

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

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, 04: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, 11:23 PM
  4. Replies: 1
    Last Post: 12-01-2002, 01:24 PM
  5. posting data to webpage...
    By Turek in forum C++ Programming
    Replies: 2
    Last Post: 07-29-2002, 11:50 AM