Impostazione credenziali in linea:
if (mUsername <> '') and (mPassword <> '') then
begin
LCredentials := TCredentialsStorage.TCredential.Create
(TAuthTargetType.Server, '', mURL, '', '');
LCredentials.Username := mUsername;
LCredentials.Password := mPassword;
NetHTTPClient1.CredentialsStorage.AddCredential(LCredentials);
NetHTTPClient1.UseDefaultCredentials := false;
end;
Oppure con l’associazione all’evento di autenticazione della classe:

procedure TForm3.NetHTTPClient1AuthEvent(const Sender: TObject; AnAuthTarget: TAuthTargetType; const ARealm, AURL: string; var AUserName, APassword: string; var AbortAuth: Boolean; var Persistence: TAuthPersistenceType); begin APassword := 'pippo'; AUserName := 'pluto'; end;
PreemptiveAuthentication:
Generalmente, il server quando riceve la richiesta risponde che necessita di utente e password per accedervi, quindi la vostra basic authentication funziona. Ci sono casi in cui invece il server viene configurato per accettare solo chiamate che in prima istanza inviano i dati di autenticazione. Per forzare la classe NetHttpClient a lavorare in questo modo:
... NetHttp := TNetHTTPClient.Create(nil); NetHttp.PreemptiveAuthentication := True; NetHttp.OnAuthEvent := HTTPAuthEvent; ...