I have a library script that makes an XMLHttpRequest to a REST API. The script works fine if I set the XMLHttpRequest URL to http://myapi.foo.com, but when I try to change the request to https://myapi.foo.com (notice the s in https), the script fails with a NETWORK_ERR and no additional error information. I am able to execute the same request from Chrome developer tools and Firefox developer tools using the https URL without issue. Has anyone else encountered this issue? Are there any other ways to make an HTTPS request in PLM Scripting?
Failing Script:
var APIURL = "https://myapi.foo.com"; var xhr = new XMLHttpRequest(); xhr.open('PUT',APIURL); xhr.send(); // fails here var response = xhr.responseText;
Successful Script:
var APIURL = "http://myapi.foo.com"; var xhr = new XMLHttpRequest(); xhr.open('PUT',APIURL); xhr.send(); var response = xhr.responseText;
Thanks!
Hi Martin,
I just performed this in Chrome, and it in fact the request stays https and even shows that the TLS/SSL certificate is valid and trusted. I was able to get a little more error information from the error log attached to my script. The full error is: [XMLHttpRequest] org.mozilla.javascript.JavaScriptException: NETWORK_ERR.
Your browser might have certificates that are not installed on the server.
The only way to diagnose is for someone with access to the server to run the following
openssl s_client -showcerts -connect myapp.foo.com:443
I don't have access to the server.
Thanks for your help Martin! It's greatly appreciated. The https://myapi.foo.com is obviously a fictitious URL, but I can provide you with my actual API URL on a private thread if it helps you to diagnose this issue.
Hi,
We have a few customers running into similar situations and posted on this Forum:
http://forums.autodesk.com/t5/fusion-lifecycle-forum/xmlhttprequest-in-action-script/m-p/4378373/hig... : Authentication required since it is a secured channel.
http://forums.autodesk.com/t5/fusion-lifecycle-forum/javascript-require-method/m-p/6388586/highlight... : Signed certificate issue
http://forums.autodesk.com/t5/fusion-lifecycle-forum/network-err-for-xlmhttprequest-in-a-script/m-p/... : Authentification should be encoded
From your snipplet, it seems that you didn't include the Authentication information in the request. If you tested with chrome you may have an active session already running. I suggest that you open a new Chrome in Incognito mode and try again the https and analyse the response.
Hi Dany,
Thank you for the recommendations. I have unfortunately viewed all of the forum threads that you reference, and they do not address the issue that i'm encountering. The API URL that i'm trying to access is a RESTful service that we developed in house. The service does not currently require authentication or an Authorization header of any kind. Additionally, the service is stateless, so no sessions are created and Chrome would not have an auth session associated with this API. We are able to successfully access this service from other environments without issue.
It would be great if the PLM scripting debugger provided a more verbose error message. We aren't sure how to proceed at this point because the error message is so generic (NETWORK_ERR).
Thank you for your assistance with this. I believe the issue was actually caused by my third party hosting provider for my external API. I was able to resolve by moving my API to a different host.