Link to home
Create AccountLog in
Avatar of enumaelis
enumaelis

asked on

IdHttp Authentication does not function

Hi, I have written a simple program for download and view a web page with IdHttp Indy component (Indy version 9). The problem occur when i try to download a page that is in a directory that requires authentication. With Internet Explorer I can easy make this by filling the classic prompt window with my username and password. With Indy I use this code:

procedure DownloadPage;
var
  lStream: TFileStream;
  sWebPage : string;
begin
  sWebPage := Edit1.Text;
  lStream:=TFileStream.Create(ExtractFilePath(Application.ExeName) + 'page.html', fmCreate or fmShareDenyNone);
  try
    IdHTTP1.Request.BasicAuthentication := True;
    IdHTTP1.Request.Username := 'myusername';
    IdHTTP1.Request.Password :=  'mypassword';
    idHTTP1.Get(sWebPage, lStream);
    IdHTTP1.Disconnect;
  except on e:exception do
    showmessage(e.Message);
  end;
 lStream.Free;
end;

On get method I receive the error: HTTP/1.1 401 Unauthorized.

Username and password are correct.
There aren't proxies
The procedure works fine with other pages that don't require authentication.

Where is the error ?

Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

Maybe it requires Digest authorization, perhaps?
Avatar of enumaelis
enumaelis

ASKER

What is Digest authorization ?

As I have said, with IE I can login without any problems or particular procedures...
Well, to use Digest auth, you need to set the Authorization property using SetHeaders.
See the Indy documentation on how to do that.
I haven't found any help in indy documentation,  but I have increase my "culture" by reading the rfc of the http protocol and so I have understood what is the digest authentication... but the problem remain the same: I have non idea on how implement the digest authorization, use the method setheaders, etc...

A code example ? Please ? :-)

P.S.: Sorry for my bad english :-(
Would you be able to provide the URL and params needed?
I can't, for security reasons, sorry...
But... It's important ?
The url has non params, the only thing that i must specify is the username and password, to obtain access to a particular folder...
I understand that ist is a POST, so there are no params in the URL, what I meant was
the params for a login.

You may not get much more help wthout the information for someone else to be able to
test this for you.
ASKER CERTIFIED SOLUTION
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thanks a lot for this code, but the error is the same: HTTP/1.1 401 Unauthorized (E.Message).

I don't want to show my server address in this "public place", can I send it to you by e-mail ?
mr_delphi_developer at yahoo dot com
I have sent to you all that you need for the test, but I can't mantain for more time the test user on the server, for security reasons... I have disabled the account, so If you want to do other tests, you must contact me for reactivate the account.

Sorry, but it's the sever of a customer, and then i can't risk...
and "so" i can't risk :-) I'm right ?
Sorry for my english :-)
I could not get it working in my tests last week. Unfortunately, I have no more time to devote to this.