The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
lpr- how to print from page to page naamas03 Shell Programming and Scripting 4 12-26-2007 03:30 AM
scp-1.2.27 man page Tornado Linux 4 03-16-2007 05:09 AM
Fetching file from windows server rochitsharma UNIX for Advanced & Expert Users 5 08-19-2006 06:51 AM
map Page Down and Page up to ] and [ buddy_amazing AIX 0 03-01-2005 11:34 AM
PHP:page.php?id= ???? perleo Shell Programming and Scripting 1 10-01-2003 06:29 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-08-2007
Registered User
 

Join Date: Nov 2005
Posts: 15
fetching a web page in C

Hello,

I'm a total newbie to HTTP commands, so I'm not sure how to do this. What I'd like is to write a C program to fetch the contents of a html page of a given address.

Could someone help with this?

Thanks in advance!
Reply With Quote
Forum Sponsor
  #2  
Old 08-08-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
what I could immediately think of is

use ( wget url ) in a system with contents redirected to a file.

But this is the not right approach.

Else

frame a http request and post it to the port 80 of the needed url
Reply With Quote
  #3  
Old 08-08-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
You basically do

Code:
fd=socket(AF_INET,SOCK_STREAM,0);
connect(fd,remoteWebserver....)
send(fd,"GET / HTTP/1.0\r\n\r\n",18);
shutdown(fd,SD_SEND);
while ((i=recv(fd,buf,sizeof(buf),0))>0)
{
      write(1,buf,i);
}
close(fd);
However, as life is short, I recommend spawning wget so it can deal with http/ftp/https etc
Reply With Quote
  #4  
Old 08-08-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
You can deal with https by using OpenSSL to provide the TCP connectivity.
Reply With Quote
  #5  
Old 08-08-2007
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,477
Don't reinvent the wheel! Use libcurl:

libcurl - C API
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0