0

http request with basic authentication does not work

Dear Ninox community!

I try to use the http-request with Basic Authentication in Ninox and it seems that it will not work. But with Postman it is working. Can somebody help me?

here ist the code:

let url := "https://httpbin.org/basic-auth/foo/bar";
let header := {
        Authorization: "Basic Zm9vOmJhcg=="
    };
Result := "";
let response := http("GET", url, header);
if response.error then
    Result := text(response.error)
else
    Result := formatJSON(response.result)
end

4 replies

null
    • szormpas
    • 1 yr ago
    • Reported - view

    Hi, try adding Accept: "application/json" into header

    let header := {
            Authorization: "Basic Zm9vOmJhcg==",
            Accept: "application/json"
        };
    
      • Hannes_Kavelar
      • 1 yr ago
      • Reported - view

      Thank you for your replay. I have already tried this before - unfortunately it doesn't  work.

    • Ninox partner
    • RoSoft_Steven.1
    • 1 yr ago
    • Reported - view

    let url := "https://httpbin.org/basic-auth/foo/bar";
    let header := {
            accept: "application/json"
        };
    let response := do as server
            http("GET", url, header)
        end;
    if response.error then
        alert("error:" + response.error)
    else
        alert("result:" + formatJSON(response.result))
    end

    With the above code I don't get an error but my result is empty. Not sure if that is supposed to be like that though.

    • Hannes_Kavelar
    • 1 yr ago
    • Reported - view

    Thank you for your replies.
    In the meantime I found the solution (see code in bold/yellow) :-)

     

    let url := "https://httpbin.org/basic-auth/foo/bar";
    let key := "Basic Zm9vOmJhcg==";
    let header := {
            Authorization: key,
            'Content-Type': "application/json"
        };
    Result := "";
    let response := do as server
            http("GET", url, header, null)
        end;
    if response.error then
        Result := text(response.error)
    else
        Result := formatJSON(response.result)
    end

Content aside

  • Status Answered
  • 1 yr agoLast active
  • 4Replies
  • 370Views
  • 3 Following