C++ CGI Accessing Webpage
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > C++ CGI Accessing Webpage




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    C++ CGI Accessing Webpage  
joseph cook


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-19-07 12:20 AM

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






[ Post a follow-up to this message ]



    Re: C++ CGI Accessing Webpage  
Robert Harris


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-19-07 12:20 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 ?

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
>





[ Post a follow-up to this message ]



    Re: C++ CGI Accessing Webpage  
joseph cook


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-19-07 12:20 AM

 
>
> 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






[ Post a follow-up to this message ]



    Re: C++ CGI Accessing Webpage  
Ian Collins


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-19-07 12:20 AM

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.





[ Post a follow-up to this message ]



    Re: C++ CGI Accessing Webpage  
SM Ryan


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-19-07 12:20 AM

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.





[ Post a follow-up to this message ]



    Re: C++ CGI Accessing Webpage  
John Tsiombikas


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-19-07 06: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/





[ Post a follow-up to this message ]



    Re: C++ CGI Accessing Webpage  
Russell Wood


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-19-07 06: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/>





[ Post a follow-up to this message ]



    Re: C++ CGI Accessing Webpage  
Logan Shaw


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-19-07 12:17 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 ?

I would use libcurl.

Or even better, I would simply avoid fetching stuff from URLs when
serving a web page.

- Logan





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:17 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register