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
-
Hi, try adding Accept: "application/json" into header
let header := { Authorization: "Basic Zm9vOmJhcg==", Accept: "application/json" };
-
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))
endWith 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.
-
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
- 357Views
-
3
Following