🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.web
4 messages
4 total messages Started by Robert Turlej Thu, 01 Dec 2005 13:50
TCppWebBrowser - how to catch errors?
#903
Author: Robert Turlej
Date: Thu, 01 Dec 2005 13:50
34 lines
1773 bytes
Hello!

In my application I use TCppWebBrowser to download by user website with  
database.
Unfortunately I have some problems:
1- when user first time use application must set on URL to the website  
with database, but when he will write wrong URL he will se page with  
infrmations 'this site couldn't be find'. I would like to catch this error  
and show other informations.
How to do it?

2- how to make blockade for some websites..for example user can't put url  
to www.google.com he can only use
only one website. For example this website can have on the top this code  
<!-- code 1999 --> so other websites without this code can't be display in  
application.

If someone can help me how to do it, I will be grateful.
I wrote posts on polish forums but noone don't know how to help me:(

All the best
Robert
Re: TCppWebBrowser - how to catch errors?
#906
Author: Remy Lebeau (TeamB)
Date: Thu, 01 Dec 2005 20:17
38 lines
2690 bytes
"Robert Turlej" <turli@poczta.fm> wrote in message
news:ops03x1nilu90ivn@turli...
Hello!

> when user first time use application must set on URL to the website
> with database, but when he will write wrong URL he will se page
> with infrmations 'this site couldn't be find'. I would like to catch this
> error and show other informations. How to do it?

That depends on what the server is actually sending back as a response.
Some servers send back actual errors when a file cannot be found.  Other
servers send back a successful response and the returned HTML then contains
the error message.  I would suggest performing all of the HTTP activity
using a separate non-visual HTTP component/library to download content, and
then display the content in the TCppWebBrowser only if it is ok to be
displayed.  That will give you much more control over the HTTP
communications as well as to validate the returned content before the user
sees it.

> how to make blockade for some websites..for example user can't
> put url to www.google.com he can only use only one website.

Don't let the user type in any URL in the first place.  Put the URL into
your code directly instead.

> For example this website can have on the top this code
> <!-- code 1999 --> so other websites without this code can't be
> display in application.

The only way to handle that is to first download the page normally and then
parse its HTML afterwards.  Although TCppWebBrowser can be used for getting
that HTML, the user will still see the page.  Again, I would suggest using a
separate non-visual HTTP component/library to download the HTML and then
display it in the TCppWebBrowser only if it is allowed to be displayed.


Gambit
Re: TCppWebBrowser - how to catch errors?
#907
Author: Robert Turlej
Date: Fri, 02 Dec 2005 09:20
10 lines
1254 bytes
Could you help me ... because I've never do something with HTTP in builder.
Do I need special library or builder 6 has it already?
If you could write me here small code to take website by HTTP to analyse I  
will be grateful.

Regards
Robert
Re: TCppWebBrowser - how to catch errors?
#925
Author: Mark Jacobs
Date: Tue, 20 Dec 2005 16:02
53 lines
3051 bytes
Robert Turlej wrote:
> Could you help me ... because I've never do something with HTTP in builder.
> Do I need special library or builder 6 has it already?
> If you could write me here small code to take website by HTTP to analyse 
> I  will be grateful.

Hope I'm not too late to help you out. This routine should give you some idea as to how to 
implement your own version. It *does not* use any 3rd party libraries. It gets the HTML 
source code of any given URL and stores it in the file specified by fnm :-

unsigned long mjgeturlconts(AnsiString url,AnsiString fnm)
{
   char *bfr; unsigned long nmbyts=0,ba,br=1; FILE *fp; AnsiString msg;
   HINTERNET hss=InternetOpen("WhateverApp",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
   if (!hss) { msg="Could not Open Internet Session"; ShowMessage(msg); return 0;}
   HINTERNET hsv=InternetOpenUrl(hss,url.c_str(),NULL,0,0,0);
   if (!hsv)
   {
     msg="Could not Open Service "+url; ShowMessage(msg);
     InternetCloseHandle(hss); return 0;
   }
   InternetQueryDataAvailable(hsv,&ba,0,0);
   if (ba==0)
   {
     msg="No Data Available at "+url; ShowMessage(msg);
     InternetCloseHandle(hss); return 0;
   }
   ba=max(10240,ba); bfr=(char *)malloc((ba+9)*sizeof(char));
   if (!bfr)
   {
     msg="Not Enough Memory - "+AnsiString(ba+9); ShowMessage(msg);
     InternetCloseHandle(hss); return 0;
   }
   fp=fopen(fnm.c_str(),"wb");
   if (!fp)
   {
     msg="Could not Open File "+fnm; ShowMessage(msg);
     free(bfr); InternetCloseHandle(hss); return 0;
   }
   while (br!=0)
   {
     InternetReadFile(hsv,bfr,ba,&br); fwrite(bfr,sizeof(char),br,fp); nmbyts+=br;
   }
   fclose(fp); InternetCloseHandle(hss); hss=NULL; free(bfr);
   return nmbyts;
}

You may need to add Borland\CBuilder5\Lib\wininet.lib or the header wininet.hpp, but you 
may not need to. HTH,

-- 
Mark Jacobs
http://www.dkcomputing.co.uk
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads