Download a file from the Internet in C ++ without using custom libraries in Linux

When I say non-standard libraries, I mean things like Boost, libCurl and everything else that can make this much easier than standard C ++. The reason for this is that I am writing an application as part of a term paper (the class is dedicated to C ++), and I need to use only standard libraries and functions.

I want to download an RSS file using a URL that will be supplied by the user (I am building a rudimentary RSS client), and the biggest problem I am facing is that I am not sure how to get the file down. Once I get through this bit, parsing it for xml tags and displaying the content will be relatively simple. I looked around and I found solutions that say they use non-standard libraries, usually libCurl. If someone could just give me a quick heads-up that I should look at this, then I would be grateful.

Also, if you think you are helping me cheat, you are not. The task is to create an application of our choice, and we evaluate our use of various functions of the language (it should contain so many classes, use these types of variables, etc.).

+5
source share
6 answers

Check out the Beej Guide to Network Programming for a quick but great introduction to sockets. If you cannot use any non-standard libraries, the only option is to manually connect to port 80 and make a request yourself.

Assuming even basic C ++ level knowledge, this should be all you need.

+8
source

Firstly, this is not possible using only standard C ++. There is no network interface in standard C ++ or standard C.

" ", , API . linux POSIX, ++, <sys/socket.h>.

: URL; IP- ; ; ; HTTP- ; HTTP ; .

, HTTP- , , HTTP , , (, ). Linux libcurl / curl wget.

+9

.

http://www.linuxhowtos.org/C_C++/socket.htm

, , HTTP-, , :

http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html

:

GET<SP><URL><SP>HTTP/1.1<CRLF>

Where:
  SP:    Single Space
  CRLF:  \r\n
  URL:   The Full URL of the page including the server name.

, ,

http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6

HTTP/1.1<SP>200<SP>OK<CRLF>
(<Header><CRLF>)*
<CRLF>
<Document>

:

  • - , 200 OK.
    • , - , .
  • 0
  • 1 , .
  • .
+3

libcurl, tcp :

GET /myurl 

(http 1.0 http 1.1)

http.

+2

You can download the source code for the standard wget utility

0
source

Since you are not allowed to use non-standard libraries, you can write your own primitive shell class for the linu "curl" command line (I assume you are using linux). Curl is a very powerful team, and it can probably do what you need.

0
source

All Articles