开发者

Is there any way to read an webpage using c++

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:

  1. establish a connection to the server
  2. send a http request
  3. 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜