Hello experts,
im trying to access nav 2018 codeunit web service from android/php (which env is on different server) but keep getting error
" Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '
http://localhost' is therefore not allowed access. The response had HTTP status code 401."
any help would be greatly apprecited
sam
“Any fool can know. The point is to understand.”
― Albert Einstein
Answers
If that is working I would expect that you have to fix the issue on the request side. The code that is making the request package that is send to the NAV app server.
sam
― Albert Einstein
soapjs.php:41:12
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://111.111.11.111:11111/NAV2018/WS/SystemService. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
― Albert Einstein
More information about Access-Control-Allow-Origin. You can configure the webserver to allow resources from another origin/server. You can also test if this is the issue by including this into the header from your PHP script.
Anyway I doubt this is a Dynamics NAV Webservice issue. You might as well try other forums
https://docs.microsoft.com/en-us/dynamics-nav/endpoints-apis-for-dynamics
https://forum.mibuso.com/discussion/71245/odata-api-page-with-cross-origin-requests#latest
> Hello experts,
>
> im trying to access nav 2018 codeunit web service from android/php (which env is on different server) but keep getting error
>
> " Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 401."
>
> any help would be greatly apprecited
>
> sam
Hi Sam, I had the exact same issue with Ionic/Javascript AJAX soap call. It looks like a direct connection to the exposed codeunit isn't supported as you can't set the CORs header/method in the NST config. I went back to the proxy method, made a C# ASMX web service that wraps the NAV gateway function. I let the ASMX handle the authentication.
Also in IIS for the proxy I set the CORs properties (Origin/Method etc.). This isn't a great solution as I'd ideally wanted to rule out using a proxy due to non on premise customers (D365 BC) but what can you do?
Anyway give me a shout if you want the code snippets, happy to share the Ajax / ASMX if it helps.
Cheers Andy, Dionix
Can you share your Ajax / ASMX solution ?