Thread View: borland.public.cppbuilder.internet.web
3 messages
3 total messages
Started by Chris
Thu, 13 Sep 2007 17:34
Indy 9 HTTP Client and Authentication?
Author: Chris
Date: Thu, 13 Sep 2007 17:34
Date: Thu, 13 Sep 2007 17:34
42 lines
2250 bytes
2250 bytes
Hi,
I am trying to use the IdHTTP component from Indy 9 to
request a JPEG file from a camera server. I was using the
CppWebBrowser component, which worked great, until I found that
I needed to handle authentication with some servers. I already
have the usernames and passwords stored and I just want to be
able to pass them to the server "on-the-fly" without even
seeing the login dialogue box. I will leave the code I was
using with the CppWebBrowser component that does work until I
try to access a server that requires authentication.
If I can do Authentication with cppWebBrowser, then I will
stick to that. I am just looking for the best solution to solve
my current problem. If Indy HTTP Client is the best solution,
then I will need some sample code as far as being able to
navigate to the webpages correctly. I can't find a c++ demo and
I am having trouble testing out the IdHTTP component.
----------------------------------------------------------------
cppWebBrowser1->Visible = false;
String ptzUrl = "http://192.168.1.101/jpg/1/image.jpg";
WideString url = ptzUrl;
cppWebBrowser1->Navigate( url.c_bstr());
String fname = "C:\\JPGTest.jpg";
URLDownloadToFile(NULL,ptzUrl.c_str(),fname.c_str(),0,NULL);
if(FileExists(fname)){
Image1->Picture->LoadFromFile(fname);
DeleteFile(fname);
}
---------------------------------------------------------------
Thanks,
Chris
Re: Indy 9 HTTP Client and Authentication?
Author: Remy Lebeau (TeamB)
Date: Thu, 13 Sep 2007 18:37
Date: Thu, 13 Sep 2007 18:37
60 lines
2379 bytes
2379 bytes
"Chris" <chris@privacy.com> wrote in message
news:46e974aa$1@newsgroups.borland.com...
> I already have the usernames and passwords stored and I
> just want to be able to pass them to the server "on-the-fly"
> without even seeing the login dialogue box.
Use the TIdHTTP's Request->Username and Request->Password properties, ie:
{
AnsiString fname = "C:\\JPGTest.jpg";
TFileStream *image = new TFileStream(fname, fmCreate);
try
{
IdHTTP1->Request->Username = "whatever";
IdHTTP1->Request->Password = "whatever";
IdHTTP1->Get("http://192.168.1.101/jpg/1/image.jpg", image);
}
__finally {
delete image;
}
try {
Image1->Picture->LoadFromFile(fname);
}
__finally {
DeleteFile(fname);
}
}
Alternatively:
{
TMemoryStream *image = new TMemory;
try
{
IdHTTP1->Request->Username = "whatever";
IdHTTP1->Request->Password = "whatever";
IdHTTP1->Get("http://192.168.1.101/jpg/1/image.jpg", image);
image->Position = 0;
TJPEGImage *jpg = new TJPEGImage;
try
{
jpg->LoadFromStream(image);
Image1->Picture->Assign(jpg);
}
__finally {
delete jpg;
}
}
__finally {
delete image;
}
}
Gambit
Re: Indy 9 HTTP Client and Authentication?
Author: Chris
Date: Thu, 13 Sep 2007 20:12
Date: Thu, 13 Sep 2007 20:12
7 lines
929 bytes
929 bytes
That helps a lot... I am having some socket issues with it, but I am finding ways of handling them. Thanks, Chris
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