BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

To Remy Lebeau - Re IdHTTP + proxy

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
Alan Garny
Guest





PostPosted: Tue Jan 13, 2004 3:09 pm    Post subject: To Remy Lebeau - Re IdHTTP + proxy Reply with quote



Thanks for your help and that of others. I have finally managed to get
IdHTTP to work with a proxy server using a BASIC authentication method.

"All" I had to do was to add a couple of lines, namely those that clear
"Request" and "ProxyParams". The rest of my code remains the same (see
below). To clear "ProxyParams" is critical, since amongst other things it
clears "ProxyServer" and "ProxyPort", which in turn clear "Authentication".

So, all I have in the end is an instance of TIdHTTP that I have filled up
with the relevant proxy information. I don't use any other Indy component.

From there, I can make calls like "IdHTTP.Get(URI, StreamFile);".

I have tried that code in the following situations:

- No proxy server: I can access the document ---> OK

- Proxy server without authentication required: I can access the
document ---> OK

- Proxy server with authentication required, BUT none provided: I canNOT
access the document ---> OK

- Proxy server with authentication required AND with some provided: I can
access the document ---> OK

Now, as I said, this only works with a basic authentication mechanism.
Ideally, I would have a solution that works with all types of
authentication... For this, I would need a proxy server that can handle
digest and/or NTLM (are there others?), which I don't. I tried to look for a
good proxy server (and easy to configure), but couldn't find one. Any idea?

Cheers, Alan.

-------------------
// Clear the request and proxy parameters

IdHTTP.Request.Clear;
IdHTTP.ProxyParams.Clear;

// Setup the proxy parameters, if necessary

If (InternetOptions.UseProxyServer) Then
With IdHTTP.ProxyParams Do Begin
// Proxy server IP address (e.g. "127.0.0.1")

ProxyServer := InternetOptions.Server;

// Proxy port (e.g. "8080")

ProxyPort := InternetOptions.Port;

// Basic authentication or not? (i.e. "True" or "False")

BasicAuthentication := InternetOptions.ProxyAuthentication;

If (InternetOptions.ProxyAuthentication) Then Begin
// Proxy username (e.g. "myname")

ProxyUsername := InternetOptions.Username;

// Have to ask the user for the password?

If (InternetOptions.AskForPassword) Then
// Ask the user for the password

With TPasswordForm.Create(Self, 'Proxy password') Do Begin
ShowModal;

// Proxy password (e.g. "mypassword")

ProxyPassword := PasswordVal.Text;

Free;
End
Else
// Retrieve the password from the internet options

ProxyPassword := Decrypt(InternetOptions.Password);
End;
End;
-------------------


Back to top
Darek Wasacz
Guest





PostPosted: Tue Feb 03, 2004 12:34 pm    Post subject: Re: To Remy Lebeau - Re IdHTTP + proxy Reply with quote




I have the problem with getting proxy settings from IE. I've been following your 'fight' with proxy. I very appreciate your effort to solve the problem :-)

Could I ask you where does the InternetOptions class come from ? Is this your component or a third-party one ?

Thank you in advance,
Darek Wasacz

Back to top
Alan Garny
Guest





PostPosted: Tue Feb 03, 2004 1:08 pm    Post subject: Re: To Remy Lebeau - Re IdHTTP + proxy Reply with quote



"Darek Wasacz" <wasacz (AT) instalsoft (DOT) com.pl> wrote

Quote:

I have the problem with getting proxy settings from IE. I've been
following your
'fight' with proxy. I very appreciate your effort to solve the problem :-)

Could I ask you where does the InternetOptions class come from ? Is this
your
component or a third-party one ?

It is a class of mine. That's where I internally store all the internet
options for my application.

Otherwise, my code that now works (seems to work at least) fine with both
Basic and NTLM authentication (as well as without any authentication at all)
is as follows:

// Set up the Internet connection

IdHTTP.Request.Clear;
IdHTTP.ProxyParams.Clear;

IdHTTP.Response.Clear;

If (InternetOptions.ConnectThroughProxyServer) Then
With IdHTTP.ProxyParams Do Begin
ProxyServer := InternetOptions.ProxyServer;
ProxyPort := InternetOptions.ProxyPort;

BasicAuthentication := InternetOptions.ProxyAuthenticationMethod =
'Basic';

If (BasicAuthentication) Then Begin
ProxyUsername := InternetOptions.ProxyAuthenticationUsername;

If (InternetOptions.ProxyAuthenticationAskForPassword) Then
With TPasswordForm.Create(Self, 'Proxy server password') Do
Begin
ShowModal;

If (ModalResult = mrOk) Then
ProxyPassword := PasswordVal.Text;

Free;
End
Else
ProxyPassword :=
Decrypt(InternetOptions.ProxyAuthenticationPassword);
End;
End;

// Check for an update

InfoFile := TFileStream.Create(InfoCORFileName, fmCreate);

ProxyErrorMsg := '';

Try
// Get the XML file that contains the versions information for COR

IdHTTP.Get(CORUpdateInfo, InfoFile);

IdHTTP.Disconnect;

InfoFile.Free;
Except
// Cannot get the version info for COR from the COR web site

Case IdHTTP.ResponseCode Of
200:
ProxyErrorMsg := 'Your proxy server cannot handle
'+InternetOptions.ProxyAuthenticationMethod+' authentication.';
407:
ProxyErrorMsg := 'Your proxy server requires explicit
authentication.';
End;

If (Not aStartup) Then
ErrorMessageDlg;

InfoFile.Free;

DeleteFile(InfoCORFileName);
End;

...



Back to top
Bryan
Guest





PostPosted: Tue Feb 03, 2004 2:09 pm    Post subject: Re: To Remy Lebeau - Re IdHTTP + proxy Reply with quote

I've tried using you code below with a few changes (internetoptions. stuff removed and hard coded settings).
Anyway, I get an error code 503 service unavailable. After looking this up, it seems that the server is busy, but I can get the file I'm after with Internet Explorer very quickly, so I'm not sure that the server is... busy. My Proxy uses Basic authentication, and port 8080. I supply the userID and Password, and the IP address of the proxy server.

Any thoughts?
Thanks
Bryan


"Alan Garny" <someone (AT) somewhere (DOT) com> wrote:
Quote:
"Darek Wasacz" <wasacz (AT) instalsoft (DOT) com.pl> wrote in message
news:401f9559$1 (AT) newsgroups (DOT) borland.com...

I have the problem with getting proxy settings from IE. I've been
following your
'fight' with proxy. I very appreciate your effort to solve the problem :-)

Could I ask you where does the InternetOptions class come from ? Is this
your
component or a third-party one ?

It is a class of mine. That's where I internally store all the internet
options for my application.

Otherwise, my code that now works (seems to work at least) fine with both
Basic and NTLM authentication (as well as without any authentication at all)
is as follows:

// Set up the Internet connection

IdHTTP.Request.Clear;
IdHTTP.ProxyParams.Clear;

IdHTTP.Response.Clear;

If (InternetOptions.ConnectThroughProxyServer) Then
With IdHTTP.ProxyParams Do Begin
ProxyServer := InternetOptions.ProxyServer;
ProxyPort := InternetOptions.ProxyPort;

BasicAuthentication := InternetOptions.ProxyAuthenticationMethod =
'Basic';

If (BasicAuthentication) Then Begin
ProxyUsername := InternetOptions.ProxyAuthenticationUsername;

If (InternetOptions.ProxyAuthenticationAskForPassword) Then
With TPasswordForm.Create(Self, 'Proxy server password') Do
Begin
ShowModal;

If (ModalResult = mrOk) Then
ProxyPassword := PasswordVal.Text;

Free;
End
Else
ProxyPassword :=
Decrypt(InternetOptions.ProxyAuthenticationPassword);
End;
End;

// Check for an update

InfoFile := TFileStream.Create(InfoCORFileName, fmCreate);

ProxyErrorMsg := '';

Try
// Get the XML file that contains the versions information for COR

IdHTTP.Get(CORUpdateInfo, InfoFile);

IdHTTP.Disconnect;

InfoFile.Free;
Except
// Cannot get the version info for COR from the COR web site

Case IdHTTP.ResponseCode Of
200:
ProxyErrorMsg := 'Your proxy server cannot handle
'+InternetOptions.ProxyAuthenticationMethod+' authentication.';
407:
ProxyErrorMsg := 'Your proxy server requires explicit
authentication.';
End;

If (Not aStartup) Then
ErrorMessageDlg;

InfoFile.Free;

DeleteFile(InfoCORFileName);
End;

...




Back to top
Alan Garny
Guest





PostPosted: Tue Feb 03, 2004 3:12 pm    Post subject: Re: To Remy Lebeau - Re IdHTTP + proxy Reply with quote

"Bryan" <here (AT) somewhere (DOT) com> wrote

Quote:
I've tried using you code below with a few changes (internetoptions.
stuff
removed and hard coded settings).
Anyway, I get an error code 503 service unavailable. After looking this
up, it
seems that the server is busy, but I can get the file I'm after with
Internet
Explorer very quickly, so I'm not sure that the server is... busy. My
Proxy
uses Basic authentication, and port 8080. I supply the userID and
Password, and
the IP address of the proxy server.

Hmm... I am not quite sure to be honest... All I know is that I have tried
NTLM and it worked and that I have a user of mine who is behind a proxy that
requires basic authentication and that it works for him too.

There are people on this newsgroup that seem to be pretty knowledgeable in
terms of proxy servers, etc. Hopefully, they will be able to help you...

Alan.



Back to top
Bryan
Guest





PostPosted: Tue Feb 03, 2004 6:45 pm    Post subject: Re: To Remy Lebeau - Re IdHTTP + proxy Reply with quote


Thanks Alan,

I'll keep looking around. Maybe someone has seen this before.
Bryan


"Alan Garny" <someone (AT) somewhere (DOT) com> wrote:
Quote:
"Bryan" <here (AT) somewhere (DOT) com> wrote in message
news:401fabac$1 (AT) newsgroups (DOT) borland.com...
I've tried using you code below with a few changes (internetoptions.
stuff
removed and hard coded settings).
Anyway, I get an error code 503 service unavailable. After looking this
up, it
seems that the server is busy, but I can get the file I'm after with
Internet
Explorer very quickly, so I'm not sure that the server is... busy. My
Proxy
uses Basic authentication, and port 8080. I supply the userID and
Password, and
the IP address of the proxy server.

Hmm... I am not quite sure to be honest... All I know is that I have tried
NTLM and it worked and that I have a user of mine who is behind a proxy that
requires basic authentication and that it works for him too.

There are people on this newsgroup that seem to be pretty knowledgeable in
terms of proxy servers, etc. Hopefully, they will be able to help you...

Alan.




Back to top
Darek Wasacz
Guest





PostPosted: Thu Feb 05, 2004 12:28 pm    Post subject: Re: To Remy Lebeau - Re IdHTTP + proxy Reply with quote


"Alan Garny" <someone (AT) somewhere (DOT) com> wrote:
Quote:

It is a class of mine. That's where I internally store all the internet
options for my application.


Does your class read proxy settings from registry (as they are saved by Internet options dialogs in IE) ?
If yes, how do you do it ?

Thanks,

Darek

Back to top
Alan Garny
Guest





PostPosted: Thu Feb 05, 2004 12:55 pm    Post subject: Re: To Remy Lebeau - Re IdHTTP + proxy Reply with quote

"Darek Wasacz" <wasacz (AT) instalsoft (DOT) com.pl> wrote

Quote:

"Alan Garny" <someone (AT) somewhere (DOT) com> wrote:

It is a class of mine. That's where I internally store all the internet
options for my application.


Does your class read proxy settings from registry (as they are saved by
Internet > options dialogs in IE) ?
If yes, how do you do it ?

No, it doesn't, because I am not quite sure how it would work if someone was
to use a different browser. So, I ask the user to provide them:

http://cor.physiol.ox.ac.uk/Screenshots/Pics/CORInternetOptions.png

Alan.



Back to top
Bryan
Guest





PostPosted: Thu Feb 05, 2004 1:19 pm    Post subject: Re: To Remy Lebeau - Re IdHTTP + proxy Reply with quote


Alan,

Is your software shareware. I'm looking for some software to try within my network that uses Indy with a Proxy server just to see if it works on my netork. I've tried numerous snipletts of code posted in this news group and still cannot successfully download a file. If it works, then I know it is possible, I just have to figure it out. I'm going crazy!

My Lan Admin says the proxy uses basic authentication. I keep getting a 503 error, but when I download with IE, no problems.

Bryan


"Alan Garny" <someone (AT) somewhere (DOT) com> wrote:
Quote:
"Darek Wasacz" <wasacz (AT) instalsoft (DOT) com.pl> wrote in message
news:4022370b$1 (AT) newsgroups (DOT) borland.com...

"Alan Garny" <someone (AT) somewhere (DOT) com> wrote:

It is a class of mine. That's where I internally store all the internet
options for my application.


Does your class read proxy settings from registry (as they are saved by
Internet > options dialogs in IE) ?
If yes, how do you do it ?

No, it doesn't, because I am not quite sure how it would work if someone was
to use a different browser. So, I ask the user to provide them:

http://cor.physiol.ox.ac.uk/Screenshots/Pics/CORInternetOptions.png

Alan.




Back to top
Alan Garny
Guest





PostPosted: Thu Feb 05, 2004 2:58 pm    Post subject: Re: To Remy Lebeau - Re IdHTTP + proxy Reply with quote

"Bryan" <me (AT) somewhere (DOT) com> wrote

Quote:
Is your software shareware. I'm looking for some software to try within
my
network that uses Indy with a Proxy server just to see if it works on my
netork. I've tried numerous snipletts of code posted in this news group
and
still cannot successfully download a file. If it works, then I know it is
possible, I just have to figure it out. I'm going crazy!

It's going to be open source, but it's not yet at the stage whereI want to
release it as such. I will try to find the time to create a small app that
allows you to download any file on a http server whether you are behind a
proxy server or not, with the proxy server either requiring authentication
(basic or NTLM) or not. Maybe this weekend...

Alan.



Back to top
Bryan
Guest





PostPosted: Thu Feb 05, 2004 3:20 pm    Post subject: Re: To Remy Lebeau - Re IdHTTP + proxy Reply with quote


Alan,

That would be above and beyond anything I would expect. THANK YOU!.

Bryan


"Alan Garny" <someone (AT) somewhere (DOT) com> wrote:
Quote:
"Bryan" <me (AT) somewhere (DOT) com> wrote in message
news:402242d4 (AT) newsgroups (DOT) borland.com...
Is your software shareware. I'm looking for some software to try within
my
network that uses Indy with a Proxy server just to see if it works on my
netork. I've tried numerous snipletts of code posted in this news group
and
still cannot successfully download a file. If it works, then I know it is
possible, I just have to figure it out. I'm going crazy!

It's going to be open source, but it's not yet at the stage whereI want to
release it as such. I will try to find the time to create a small app that
allows you to download any file on a http server whether you are behind a
proxy server or not, with the proxy server either requiring authentication
(basic or NTLM) or not. Maybe this weekend...

Alan.




Back to top
Alan Garny
Guest





PostPosted: Sun Feb 08, 2004 8:19 pm    Post subject: Re: To Remy Lebeau - Re IdHTTP + proxy Reply with quote

"Bryan" <me (AT) somewhere (DOT) com> wrote

Quote:
That would be above and beyond anything I would expect. THANK YOU!.

Ok, I have put a very small example of that in b.p.attachments. I have tried
it with a proxy server that requires basic authentication and, as far as I
can tell, it works fine.

Something very weird, though, is that if I don't specify a proxy server,
then it doesn't seem to be working (!!!). If, within the Delphi IDE, I trace
the program, then it works! I am sorry, but I really don't have the time to
figure out what is going on here. I know that it works fine in my normal
application (I use that feature, i.e. download without a proxy server, at
least once a week and I have never had any problem with it).

Anyway, hope that helps...

Alan.



Back to top
Bryan
Guest





PostPosted: Sun Feb 08, 2004 9:40 pm    Post subject: Re: To Remy Lebeau - Re IdHTTP + proxy Reply with quote

Alan,

Thanks for your help! I'll give it a try.

Bryan



"Alan Garny" <someone (AT) somewhere (DOT) com> wrote:
Quote:
"Bryan" <me (AT) somewhere (DOT) com> wrote in message
news:40225f3f$1 (AT) newsgroups (DOT) borland.com...
That would be above and beyond anything I would expect. THANK YOU!.

Ok, I have put a very small example of that in b.p.attachments. I have tried
it with a proxy server that requires basic authentication and, as far as I
can tell, it works fine.

Something very weird, though, is that if I don't specify a proxy server,
then it doesn't seem to be working (!!!). If, within the Delphi IDE, I trace
the program, then it works! I am sorry, but I really don't have the time to
figure out what is going on here. I know that it works fine in my normal
application (I use that feature, i.e. download without a proxy server, at
least once a week and I have never had any problem with it).

Anyway, hope that helps...

Alan.




Back to top
Bryan
Guest





PostPosted: Mon Feb 09, 2004 8:25 pm    Post subject: Re: To Remy Lebeau - Re IdHTTP + proxy Reply with quote


Alan,

I gave your test program a try and I still get a 403 Forbidden Error. I tried several different settings with no luck. I guess I'll have to get with the Lan shop again to find out what they are doing. Maybe they can trace the packets to and through the proxy.

Thank you very much for your help.
I'll post the solution if an when I get one.
Bryan


"Alan Garny" <someone (AT) somewhere (DOT) com> wrote:
Quote:
"Bryan" <me (AT) somewhere (DOT) com> wrote in message
news:40225f3f$1 (AT) newsgroups (DOT) borland.com...
That would be above and beyond anything I would expect. THANK YOU!.

Ok, I have put a very small example of that in b.p.attachments. I have tried
it with a proxy server that requires basic authentication and, as far as I
can tell, it works fine.

Something very weird, though, is that if I don't specify a proxy server,
then it doesn't seem to be working (!!!). If, within the Delphi IDE, I trace
the program, then it works! I am sorry, but I really don't have the time to
figure out what is going on here. I know that it works fine in my normal
application (I use that feature, i.e. download without a proxy server, at
least once a week and I have never had any problem with it).

Anyway, hope that helps...

Alan.




Back to top
Alan Garny
Guest





PostPosted: Mon Feb 09, 2004 9:48 pm    Post subject: Re: To Remy Lebeau - Re IdHTTP + proxy Reply with quote

"Bryan" <me (AT) somewhere (DOT) com> wrote

Quote:
I gave your test program a try and I still get a 403 Forbidden Error. I
tried
several different settings with no luck. I guess I'll have to get with the
Lan
shop again to find out what they are doing. Maybe they can trace the
packets to
and through the proxy.

Hmm... very strange... As I told you, I tried with a proxy server that
requires Basic authentication and, surely, if I either mistype my login
and/or password, then I can download anymore, while it works fine as soon as
both my login and password are correct. The same was observed by users of
mine who are behind a proxy server that requires that type of
authentication...

Quote:
Thank you very much for your help.
I'll post the solution if an when I get one.

That would be much appreciated and sorry I couldn't be of much more help...

Alan.



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.