|
Home > Archive > Unix Programming > August 2007 > C++ CGI Accessing Webpage
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
C++ CGI Accessing Webpage
|
|
| joseph cook 2007-08-18, 7:20 pm |
| In PHP, I can access a webpage data simply by $fp = fopen("http://
www.url.com");
How can I do the equivalant using a C++ CGI on UNIX? All my searched
just pile lots of windows crap on me (yuck!)
Can anyone point me to any resources ?
I guess ifstream("http://www.url.com") is asking too much ?
thanks,
Joe C
| |
| Robert Harris 2007-08-18, 7:20 pm |
| joseph cook wrote:
> In PHP, I can access a webpage data simply by $fp = fopen("http://
> www.url.com");
>
> How can I do the equivalant using a C++ CGI on UNIX? All my searched
> just pile lots of windows crap on me (yuck!)
>
> Can anyone point me to any resources ?
The CGI spec is at <http://www.ietf.org/rfc/rfc3875.txt>
>
> I guess ifstream("http://www.url.com") is asking too much ?
Yes. Fetching web pages from C++ is not completely straightforward!
Robert
>
> thanks,
> Joe C
>
| |
| joseph cook 2007-08-18, 7:20 pm |
|
>
> Yes. Fetching web pages from C++ is not completely straightforward!
>
> Robert
Thanks for that. It's way over my head though! I got it working by
calling system(wget url -O output), and then ifstream("output");
it seems to be plenty fast enough for my needs. After doing so much
php for web apps, I am already seeing things come back and calculate
an order of magnitude faster, if not more. Of course, this could be
due to the fact that I have 11 years C++ under my belt, and only done
casual php coding.
Thanks
| |
| Ian Collins 2007-08-18, 7:20 pm |
| joseph cook wrote:
>
> Thanks for that. It's way over my head though! I got it working by
> calling system(wget url -O output), and then ifstream("output");
>
How about using
popen( "wget url -O -", "r" );
--
Ian Collins.
| |
| SM Ryan 2007-08-18, 7:20 pm |
| joseph cook <joecook@gmail.com> wrote:
# In PHP, I can access a webpage data simply by $fp = fopen("http://
# www.url.com");
#
# How can I do the equivalant using a C++ CGI on UNIX? All my searched
# just pile lots of windows crap on me (yuck!)
Are you taking about as a client or a server? A client does not
know how an http request is fulfilled. (The URL hints, but the
server is not constrained by those hints.)
--
SM Ryan http://www.rawbw.com/~wyrmwif/
I think that's kinda of personal; I don't think I should answer that.
| |
| John Tsiombikas 2007-08-19, 1:19 am |
| On 2007-08-18, joseph cook <joecook@gmail.com> wrote:
>
> I guess ifstream("http://www.url.com") is asking too much ?
Hehe, yeah, ifstream only works with files 
You could just open a socket, connect to the http server and feed it a
custom-made HTTP request (just to get a grasp of the process), just
google for HTTP RFC (can't be bothered to look up the number right now).
However, in a real program, I would suggest using libcurl. It's a free
cross platform library for handling a number of network protocols (HTTP
among them), and it's extremely easy to use. Check it out.
--
John Tsiombikas (Nuclear / Mindlapse)
nuclear@siggraph.org
http://nuclear.demoscene.gr/
| |
| Russell Wood 2007-08-19, 1:19 am |
| On 2007-08-18, joseph cook <joecook@gmail.com> wrote:
> In PHP, I can access a webpage data simply by $fp = fopen("http://
> www.url.com");
>
> How can I do the equivalant using a C++ CGI on UNIX? All my searched
> just pile lots of windows crap on me (yuck!)
>
> Can anyone point me to any resources ?
>
> I guess ifstream("http://www.url.com") is asking too much ?
Man socket
--
Russell Wood
<http://www.dynode.net/~rjw/>
| |
| Logan Shaw 2007-08-19, 7:17 am |
| joseph cook wrote:
> In PHP, I can access a webpage data simply by $fp = fopen("http://
> www.url.com");
>
> How can I do the equivalant using a C++ CGI on UNIX? All my searched
> just pile lots of windows crap on me (yuck!)
>
> Can anyone point me to any resources ?
I would use libcurl.
Or even better, I would simply avoid fetching stuff from URLs when
serving a web page.
- Logan
|
|
|
|
|