There are APIs like Qlik Sense (https://help.qlik.com/en-US/sense-developer/November2019/Subsystems/Platform/Content/Sense_PlatformOverview/Integration/expose-qlik-sense.htm) who uses Cookies for Authentication. We are currently not able to use those APIs in the Cloud, because HttpClient by default don't transfers the header "Cookie". All other header can be set and will be transferred.
C# Console Example:
var handler = new HttpClientHandler { UseCookies = false };
using (var client = new HttpClient(handler))
{
client.DefaultRequestHeaders.Add("Cookie", "cookiename=value");
var response = await client.GetAsync("https://server/api");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
Comments
This would be a really helpful feature as some APIs do not support other mechanisms than cookies.
Category: Development
Its a bit of joke really that to use cookies in AL we have to resort to using HttpWebRequest when MS have this on the HttpWebRequest page (HttpWebRequest Class (System.Net) | Microsoft Learn) " ImportantWe don't recommend that you use HttpWebRequest for new development. Instead, use the System.Net.Http.HttpClient class."
Category: Development
I don't understand how you can ship HttpClient where it's impossible to use cookies.
I get that the underlying type is .NET HttpClient, but you could at least instantiate it in such a way where the cookies we add aren't overwritten (since the .NET HttpClient does support this).
Category: Development
On HTTPCLIENT object seems that not all headers from the http response are accessible and not all headers can be setted.
[...]
soap_HttpResponseMessage.Content.ReadAs(ResponseText);
ResponseHeaders := soap_HttpResponseMessage.Headers;
soap_HttpResponseMessage.Content.GetHeaders(ResponseHeaders);
if not soap_HttpClient.Get(UrlLoc, soap_HttpResponseMessage) then
createError('Error', 'Error on call');
if not soap_HttpResponseMessage.IsSuccessStatusCode then
createError('Error: ' + FORMAT(soap_HttpResponseMessage.HttpStatusCode), soap_HttpResponseMessage.ReasonPhrase);
soap_HttpResponseMessage.Content.ReadAs(ResponseText);
[...]
Category: Development
AL Example, where the HTTP header "TestHeader" will be transferred to the server, but the HTTP header "Cookie" not.
trigger OnAction()
var
WebClient: HttpClient;
ResponseMessage: HttpResponseMessage;
Response: Text;
begin
WebClient.DefaultRequestHeaders.Add('TestHeader', 'cookiename=value');
WebClient.DefaultRequestHeaders.Add('Cookie', 'cookiename=value');
WebClient.Get('https://server/api', ResponseMessage);
ResponseMessage.Content().ReadAs(Response);
Message(Response);
end;
Category: Development
Business Central Team (administrator)
Thank you for this suggestion! Currently this is not on our roadmap. We are tracking this idea and if it gathers more votes and comments we will consider it in the future.
Best regards,
Business Central Team