HttpClient and TLS compatibility

VishalAgVishalAg Member Posts: 5
edited 2022-04-08 in NAV Three Tier
Hi,

Currently I have been trying to integrate a website with Business Central 19 saas.
The website doesn't have a SSL certificate, so I need to skip its verification when sending https GET request.

Earlier I used ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 to use TLS protocol while calling a webservices but currently I think the Business Central doesn't support the same.

Can anyone let me know a way to call 3rd party web services using TLS protocol.

Thank You.

@kriki @ftornero @RockWithNAV @DenSter @rkaufmann @ara3n @vaprog or anyone who can help

Best Answer

  • ftorneroftornero Member Posts: 464
    Answer ✓
    Hello @VishalAg,

    In the other hand, usually for the basic authorization, like the one you are using, the value is preceding by Basic and an space, like this:
    AuthString := 'Basic ' + Base64.ToBase64(AuthString);
    

Answers

  • ilkaysenerilkaysener Member Posts: 2
    Hi,

    Maybe you can create an Azure function and write an HttpClient method as you want using the necessary .Net objects and then call it from within Business Central.

    I'm very new to the world of Business Central, sorry if I misunderstood or gave any wrong information.

    https://docs.microsoft.com/en-us/learn/modules/use-azure-functions/
  • ftorneroftornero Member Posts: 464
    Hello @VishalAg,

    I don't know if you can share more information about the issue, how are you doing the call to the remote website, what is the return that you got, etc.

    Regards.
  • VishalAgVishalAg Member Posts: 5
    @ftornero, I am using Httpclient to make calls. In postman when I make call, I can disable the Veriy SSL and it works fine. But in saas model, I am unable to find such option which will disable the SSL verification or make the use of TLS instead of SSL.

    Below is the code being used:
    SalesSetup.GET;
    SalesSetup.TestField("API Consumer Key");
    SalesSetup.TestField("API Consumer Secret");
    SalesSetup.TestField("API Default Customer");
    SalesSetup.TestField("API Link (All Orders)");
    AuthString := SalesSetup."API Consumer Key" + ':' + SalesSetup."API Consumer Secret";
    AuthString := Base64.ToBase64(AuthString);
    URL := SalesSetup."API Link (All Orders)";
    HttpClient.DefaultRequestHeaders.Add('Authorization', AuthString);
    HttpClient.DefaultRequestHeaders.Add('User-Agent', 'Dynamics 365');

    IF NOT HttpClient.GET(URL, ResponseMessage) then
    Error('The call to webservice failed.');

    IF Not ResponseMessage.IsSuccessStatusCode THEN
    Error('The webservice returned an error message:\\' +
    'Status Code: %1\' +
    'Description: %2',
    ResponseMessage.HttpStatusCode, ResponseMessage.ReasonPhrase);
  • ftorneroftornero Member Posts: 464
    Hello @VishalAg,

    And what response do you got ?.
  • ftorneroftornero Member Posts: 464
    Answer ✓
    Hello @VishalAg,

    In the other hand, usually for the basic authorization, like the one you are using, the value is preceding by Basic and an space, like this:
    AuthString := 'Basic ' + Base64.ToBase64(AuthString);
    
  • VishalAgVishalAg Member Posts: 5
    @ftornero thanks for help. Attaching Basic as a keyword worked.
Sign In or Register to comment.