Access internet

This is a discussion on Access internet within the C++ Programming forums, part of the General Programming Boards category; I'v only very little knowledge of programming and completely new to C/C++. I've an interesting 1st project in mind that ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,755
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,652
    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
    22,144
    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.
    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

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,755
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 09: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, 04:43 PM
  5. Remote Access Robot control via the internet
    By Valdim in forum C++ Programming
    Replies: 1
    Last Post: 09-06-2001, 04:07 AM

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