I kno开发者_开发百科w that we can retrieve a webpage content through curl http://curl.haxx.se/ but is there any native way to retrieve the content of an webpage using c++ without using any library?
You will always need some kind of library in order to establish a network connection (I count OS APIs as libraries). That aside, you would have to:
- establish a connection to the server
- send a http request
- receive and handle the http response
You can implement these steps by hand, but that really is a pain, especially because http is quite a complex protocol (even if you only implement the stuff you actually use, enough remains).
If you use Windows, you can use functions below
InternetOpen() - Initializes an application's use of the WinINet functions. http://msdn.microsoft.com/en-us/library/aa385096(VS.85).aspx
InternetOpenUrl() - Opens a resource specified by a complete FTP, Gopher, or HTTP URL. http://msdn.microsoft.com/en-us/library/aa385098(VS.85).aspx
InternetReadFile() - Reads data from a handle opened by the InternetOpenUrl http://msdn.microsoft.com/en-us/library/aa385103(VS.85).aspx
InternetCloseHandle() - Closes a single Internet handle http://msdn.microsoft.com/en-us/library/aa384350(VS.85).aspx
Hope it helps
PS: or you can use a more convenient function
URLDownloadToFile() - Downloads bits from the Internet and saves them to a file. http://msdn.microsoft.com/en-us/library/ms775123(v=vs.85).aspx
精彩评论