Business Central API call with HttpClient.UseWindowsAuthentication and Error 401
Hello Team!
Today we will work with next scenario:
1. Work with AL language
2. We have on-premise Business Central Spring'19 release (any localization) installed on Azure VM with DNS (like myvm.westeurope.cloudapp.azure.com).
UseWindowsAuthentication feature were introduced at December'18 and works only for on-premise BC
3. We have Windows credentials on Business Central instance.
4. We are planning to send data (call an BC API) from same tenant to same tenant. So I just want to replicate data between 2 companies on the same database using API.
5. When i'm calling BC API with Postman - everything works smoothly, but when i'm using
Client.UseWindowsAuthentication(Username, Password);
Client.Get(URL, ResponseMessage);
nothing works. And this construction also not working:
Client.UseWindowsAuthentication(Username, Password, Domain);
Client.Get(URL, ResponseMessage);
"Not working" - means I'm getting Error 401 Unauthorized each call instead of getting 200 Ok
So after googling and asking in Yammer I found next solution:
I used 2nd method:
Specify host names
To specify the host names that are mapped to the loopback address and can connect to Web sites on your computer, follow these steps:
- Set the DisableStrictNameChecking registry entry to 1. (http://www.happysysadm.com/2011/11/setting-disablestrictnamechecking-in.html)
- Click Start, click Run, type regedit, and then click OK.
- Locate and then click the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0 - Right-click MSV1_0, point to
New, and then click Multi-String Value. - In the Name column, type
BackConnectionHostNames, and then press ENTER. - Right-click BackConnectionHostNames, and then click Modify.
- In the Value data box, type the DNS alias, that is used for Azure VM, and then click OK.
Note Type each host name on a separate line.
Note If the BackConnectionHostNames registry entry exists as a REG_DWORD type, you have to delete the BackConnectionHostNames registry entry. - Exit Registry Editor, and then restart the BC instance.
After that it started working as it planned.
Hope it will help you and happy sysadmin day!

Like
Report
*This post is locked for comments