C++ reading info from a webpage

Programming, for all ages and all languages.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: C++ reading info from a webpage

Post by JamesM »

GhostXoPCorp wrote:i want my program to read just a line of information from a cite, for example a "daily update" and just have my program copy that information like this


http://www.examplesite.com

webpage:

Daily Update: First Day Of Program Release

end of webpage
thats all the site willl display

how can i get my C++ win32 program to read that line from that site?
Why not use a language and toolset suited to the task?
Gigasoft
Member
Member
Posts: 855
Joined: Sat Nov 21, 2009 5:11 pm

Re: C++ reading info from a webpage

Post by Gigasoft »

On Windows, it doesn't get much simpler than using the InternetOpen, InternetOpenUrl and InternetReadFile functions. It basically takes care of everything for you.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: C++ reading info from a webpage

Post by Solar »

Absolutely +1 to Gigasoft. Nothing beats somebody actually answering the question (how to do it in C++ using Windows API).
Every good solution is obvious once you've found it.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: C++ reading info from a webpage

Post by Owen »

Gigasoft wrote:Send won't return until it has sent everything or it fails, unless the socket is set to non-blocking mode. Recv, however, may return less data than requested.
Not the case, though I understand that the wording of the relevant man pages can be ambiguous.
If space is not available at the sending socket to hold the message to be transmitted, and the socket file descriptor does not have O_NONBLOCK set, send() shall block until space is available. If space is not available at the sending socket to hold the message to be transmitted, and the socket file descriptor does have O_NONBLOCK set, send() shall fail. The select() and poll() functions can be used to determine when it is possible to send more data. [SUS3]
So, indeed send will wait for buffer space to be available. However, for TCP it doesn't guarantee that the whole buffer you pass to send will be sent in one go. You must check the return value and manually ensure this.
Post Reply