Discussion:
TIdHTTP Post error 401 Unauthorized
(too old to reply)
Hipolito Lopez
2008-04-24 00:38:55 UTC
Permalink
I'm trying to do a post to a local url in my network using this
code, but I'm getting 401 error (HTTP/1.1 401 Unauthorized), what can I do? or search for? (the machine where I running this is out the domain)

TMemoryStream *aStream = new TMemoryStream();
TStringStream *StrStream = new TStringStream(NULL);

TStringList *a = new TStringList();
TIdURI *uri = new TIdURI("");
TIdMultiPartFormDataStream *Params = new TIdMultiPartFormDataStream();

Params->AddFormField("tarjeta", codta);
Params->AddFormField("tipo", tipo);
Params->AddFormField("monto", monto);
Params->AddFormField("cargo", cargo);
Params->AddFormField("idcajero", idcajero);
Params->AddFormField("cajero", cajero);

IdHTTP1->Request->Clear();
IdHTTP1->Request->BasicAuthentication = true;
IdHTTP1->Request->Username = txtUser->Text;
IdHTTP1->Request->Password = txtPwd->Text;

IdHTTP1->Post(txtUrl->Text, Params, aStream);

aStream->Seek(0, soFromBeginning);
aStream->SaveToStream(StrStream);
StrStream->Seek(0, soFromBeginning);

ShowMessage(StrStream->DataString);

delete a;
delete aStream;
delete Params;
delete uri;
delete StrStream;
Remy Lebeau (TeamB)
2008-04-24 00:45:19 UTC
Permalink
Post by Hipolito Lopez
I'm trying to do a post to a local url in my network using this
code, but I'm getting 401 error (HTTP/1.1 401 Unauthorized),
what can I do?
The server requires authentication that you are not providing. Make sure
you have included the appropriate IdAuthentication...hpp header file into
your code, such as IdAuthenticationDigest.hpp.


Gambit
Hipolito Lopez
2008-04-24 01:08:35 UTC
Permalink
Thanks Remy for you help.
But how do I know where file (header) to use?
Post by Remy Lebeau (TeamB)
you have included the appropriate IdAuthentication...hpp header file into
Remy Lebeau (TeamB)
2008-04-24 16:56:19 UTC
Permalink
Post by Hipolito Lopez
But how do I know where file (header) to use?
Well, first you need to find out which authentication(s) the server supports
in the first place. After the server's reply comes back, you can look in
the Response->WWWAuthenticate property to see which authentication(s) the
server asked for.


Gambit
Hipolito Lopez
2008-04-26 04:01:57 UTC
Permalink
Hi Remy,
Post by Remy Lebeau (TeamB)
Well, first you need to find out which authentication(s) the server supports
in the first place.
The server send this to me:

HTTP/1.1 401 Unauthorized
Content-Length: 1539
Content-Type: text/html
Server: Microsoft-IIS/6.0
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
Date: Sat, 26 Apr 2008 03:37:40 GMT
Connection: close

I see that is using NTML, but I don't know what is
WWW-Authenticate: Negotiate


What can I do?
Remy Lebeau (TeamB)
2008-04-28 17:07:36 UTC
Permalink
Post by Hipolito Lopez
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
You did not say which version of Indy you are using. Indy 9 does not
support "Negotiate" at all, but it does support ""NTLM". Indy 10 supports
both. Both Indy 9 and 10 have IdAuthenticationSSPI ("NTLM" in Indy 9,
"Negotiate" and "NTLM" in Indy 10) and IdAuthenticationNTLM (just "NTLM" in
both) units available.


Gambit

Loading...