The "Authorization" request header for basic authentication is a string that starts with "Basic ". Then follows a BASE64 codes string of "username:password".
For Base64 encoding you may use the CryptBinaryToStringW function of Windows API:
Function Boolean CryptBinaryToString ( &
blob pbBinary, &
ulong cbBinary, &
ulong dwFlags, &
Ref string pszString, &
Ref ulong pcchString) Library "Crypt32.dll" Alias For "CryptBinaryToStringW"
blob lblob_text
string ls_b64
unsignedlong lul_buflen
CONSTANT ulong CRYPT_STRING_BASE64 = 1
CONSTANT ulong CRYPT_STRING_NOCRLF = 1073741824
IF IsNull (as_text) THEN return as_text
lblob_text = Blob (as_text, EncodingUTF8!)
ls_b64 = Space (2 + 1.5 * (Len (lblob_text) + 2))
lul_buflen = Len (ls_b64)
IF Not CryptBinaryToString (lblob_text, Len (lblob_text), CRYPT_STRING_BASE64 + CRYPT_STRING_NOCRLF, ls_b64, lul_buflen) THEN
// error handling
End If
return ls_b64
Thanks for your reply - however that is not working - i still get 401 {"error":"Unauthorized"}
regards
Andrew
One time saving trick I'll use is to connect to the service via SoapUI, and look at how it configures the request headers. Then I just reproduce that in my code and clean it up as needed.
A working example on my end using httpclient:
http.SecureProtocol=0 // Defaults to the server security setting
http.SetRequestHeader("Accept", "*/*")
http.SetRequestHeader("Accept-Language", "en")
http.SetRequestHeader("Connection", "close")
http.SetRequestHeader("Content-Type", "application/json")
http.SetRequestHeader("Host", ls_host)
http.SetRequestHeader("User-Agent", "Apache-HttpClient/4.1.1 (java 1.5)")
http.SetRequestHeader("Authorization", "Bearer " + ls_token)
ll_rtn = http.SendRequest('GET', ls_url)
ll_http_code = http.GetResponseStatusCode()
ls_ContentType = http.GetResponseHeader("Content-Type")
ls_AllHeaders = http.GetResponseHeaders()
http.GetResponseBody(ls_json)