Thread: Access internet

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    4

    Access internet

    I'v only very little knowledge of programming and completely new to C/C++. I've an interesting 1st project in mind that should be mostly doable, educational and usefull. At this moment I see only one serious obstacle, accessing the internet.

    I need a way to handle internet access from my program. I've found curl and curlpp, but with my present knowledge they're too complicated for me. I'm looking for a function or other code that relieves me from handling all the overhead. Ideally I call a function, feed it with UID, PW, URL and the type of request (get, post etc) and it returns a string with the result. This without me having to worry about cookies, keeping the connection alive etc.

    Does anyone know where I can find this kind of code?

    Thanks!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    libcurl - C API
    Well if the "easy" interface is still too difficult for you, then I would suggest you spend 6 months learning the basics.

    > I'v only very little knowledge of programming and completely new to C/C++
    Or you turn to a nice "hold your hand" language like python.
    How to read a web page using Python | eHow.com
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    4
    Sorry, don't see how switching language is going to help me. I would still have to dive into the http protocol to figure out how to handle all the overhead like cookies and the cookiejar etc and write code for it. Maybe I'm wrong, but I don't see how I can post data without this.

    I want to concentrate on learning the basics of c/c++ in an interesting 1st project. A project that motivates me as it is usefull to me. A project that apart from the internet access should be ok for me as a complete beginner. I can cut it up in small easy manageable parts.

    Though I did not find it (yet) I would imagine some kind of browser function that accepts urls and handles all the overhead would be available.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Did you check out the libcurl page to which Salem linked? There is a page full of examples.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    4
    I've seen the examples. I'm convinced it is very easy when you know the http protocol and c++. Both of them I don't know. If I just look at the examples I see about 10 lines of code for a simple get or post request. The cookie example has 3 screens of code! I'm at the "hello world" level now. I'm able to get some input, manipulate a variable and provide some output. In a browser I don't have to bother about options, cookies etc, I only select a link. I would expect something like that to be available in a c library. Just provide the url and return te result. Apparently I'm wrong

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by BoerBert
    Sorry, don't see how switching language is going to help me. I would still have to dive into the http protocol to figure out how to handle all the overhead like cookies and the cookiejar etc and write code for it. Maybe I'm wrong, but I don't see how I can post data without this.
    No, you should not need "to dive into the http protocol", though at least some understanding of it would be useful. Programming languages that tend to be more commonly used for web programming than C and C++ also tend to have either built-in or better (as in a higher level of abstraction) library support for what you want to do. For example, using the suggestion of Python, your request could be answered with:
    Code:
    import urllib
    remote_file = urllib.urlopen('http://example.com')
    print(remote_file.read())
    In PHP, with url_fopen_wrappers enabled, you could write:
    Code:
    echo htmlspecialchars(file_get_contents('http://example.com'));
    Quote Originally Posted by BoerBert
    I've seen the examples. I'm convinced it is very easy when you know the http protocol and c++. Both of them I don't know. (...) I'm at the "hello world" level now. I'm able to get some input, manipulate a variable and provide some output.
    Sorry, but you are trying to run before you can walk. Not knowing HTTP is one thing; not knowing even the basics of C++ spells disaster. I agree with Salem: you need to spend time learning the basics first. For example, obtain a copy of Accelerated C++ and work through it.

    Quote Originally Posted by BoerBert
    If I just look at the examples I see about 10 lines of code for a simple get or post request. The cookie example has 3 screens of code!
    Well, I can understand a newbie being initially intimidated by "3 screens of code", but that is irrelevant anyway since you don't intend to deal with cookies. If "about 10 lines of code" freaks you out, then you are really not ready.

    Quote Originally Posted by BoerBert
    In a browser I don't have to bother about options, cookies etc, I only select a link. I would expect something like that to be available in a c library. Just provide the url and return te result. Apparently I'm wrong
    Have you even tried the simple HTTP example, which "shows how to get a remote web page in only four libcurl function calls"?
    Last edited by laserlight; 11-14-2010 at 12:43 PM.
    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

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Methinks the OP is wanting to walk into a cake shop and buy an almost complete cake.

    Not realising that C is more like a vast pantry of basic ingredients. Very basic in fact.
    The eggs to make the cake are still in the chicken!

    Sure, you can make any thing you can possibly imagine, but it takes a lot more effort than simply finding something where 99% of the grunt work has already been done.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Nov 2010
    Posts
    4
    Quote Originally Posted by laserlight View Post
    Well, I can understand a newbie being initially intimidated by "3 screens of code", but that is irrelevant anyway since you don't intend to deal with cookies. If "about 10 lines of code" freaks you out, then you are really not ready.
    The point is not that I'm intimidated by 3 screens of code. The point is that it's a big leap to start with coding a 'complete' webbrowser when you just start out with a programming language. To me it seems pretty standard stuff to execute a few http get and post commands. Other, more ancient, IO operations like reading and writing to a file etc are even included in the standard library. No worries about the overhead there. I remember times you had to worry about buffer states when outputting! Consequently I expected that a standard solution is available. If not, fair enough, just tell so instead of making all kinds of assumptions.

    I'm not trying to run before I can walk. The project I've in mind is quite simple. Most of what I need is covered in the beginners tutorial on this site! Only major issue is I've to be able to access webpages and post results. In my perception pretty standard stuff used in many modern programs. In ancient times when I had to learn the basics of Pascal in school I started out with a bunch of useless programs like bubblesort, finding prime numbers etc. I can do that again, I prefer however to learn by doing something more usefull.

    Well, clearly I'm mistaken in my expectations. Fair enough, lets forget about it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ww hosting and SSH access
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 04-07-2005, 08:49 AM
  2. I've decided Bush is right, and we're wrong.
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-30-2005, 09:16 PM
  3. will not erase this history for internet explorer
    By HelpPLease123 in forum Tech Board
    Replies: 8
    Last Post: 11-02-2002, 01:18 AM
  4. Access books, tutorials, source
    By maes in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 04-17-2002, 03:43 PM
  5. Remote Access Robot control via the internet
    By Valdim in forum C++ Programming
    Replies: 1
    Last Post: 09-06-2001, 03:07 AM