Hi,
I’m trying to create an http basic auth header to use with the http client. I’m brand new to prolog, so please forgive my lack of knowledge. Please find my latest attempt below. I don’t really understand what I’m doing wrong.
:- use_module(library(http/http_client)).
:- use_module(library(http/http_json)).
:- use_module(library(base64)).
basic_auth(Header) :-
format(atom(Credentials), '~w:~w', ['user', 'password']), % Concatenate username and password
base64(Credentials, Encoded), % Base64 encode the concatenated string
format(atom(Header), 'Authorization: Basic ~w', [Encoded]). % Create the header with the "Basic" scheme
% Base URL for the server
base_url('http://localhost/api').
% Create a doc
create_doc(Document) :-
base_url(BaseURL), % get base url
basic_auth(Header), % get auth header
atomic_list_concat([BaseURL, '/document'], URL), % build full url
http_post(URL, json(_{name: testme}), _, [authorization(Header), json_object(dict)]). % post to server
I get the error below:
ERROR: Domain error: authorization' expected, found
‘Authorization: Basic dXNlcjpwYXNzd29yZA==’’
Thanks,
-S