Setting authDetails programatically

  1. 5 years ago

    apt

    17 Jun 2018 User since 2018
    Edited 5 years ago by apt

    I'm starting to play the HTTPClient for a simple REST api app but finding it hard to work out how to set the authDetails from code. I've added it in the HTTP Client server properties from the UI and its working but I want to be able to specify these setting from code based on a users input (textfield).

    Any pointers would be useful.

    Thanks

  2. apt

    18 Jun 2018 User since 2018

    Any ideas?

  3. andrea

    18 Jun 2018 Administrator User since 2016

    Hi @apt, the authDetails property of an HTTPClient object is a Map . For example, if the "Authentication Type" is "Basic Auth", its value is something like [username:xxx, password:xxx].
    If you want to set it programmatically with, for example, the values from two text fields:
    HTTPClient1.authDetails = ["username": TextField1.text, "password": TextField2.text]

  4. apt

    18 Jun 2018 User since 2018

    I’ll give that a go thanks.

  5. apt

    23 Jun 2018 User since 2018

    Ok so I have the following code:

    HTTPClient1.authDetails = ["username": Window3.server_field.text, "password": Window3.password_field.text];

    I have it in the Load event on the HTTPClient1 but its not triggering. Any ideas?

  6. andrea

    23 Jun 2018 Administrator User since 2016

    @apt,
    what is not triggering exactly?

    Some ideas:

    • when the Load event of the HTTPClient1 is invoked the two text fields have empty values or are not yet loaded (you can check this by adding a Console.write("server_field: \(Window3.server_field.text)"))
    • the HTTPClient1.authDetails is set correctly but it is never used because its HTTPRequest subnode doesn't run. An HTTPRequest runs automatically if configured as a dataset of a control (for example a table, a collection, etc.) or if it is used as a source object of a Binding, otherwise you should run programmatically with HTTPClient1.YourRequest.run()

or Sign Up to reply!