I'm trying to call esri/request on a page that requires username/password, but when I do, I get the following error:
esri.config.defaults.io.proxyUrl is not set. If making a request to a CORS enabled server, please push the domain into esri.config.defaults.io.corsEnabledServers
Error: "Unable to load https://<myserver> status: 0"
But if I do add the domain into corsEnabledServers, I get this error:
XMLHttpRequest cannot load https://<myserver>. 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.
Error: Unable to load https://<myserver>' status: 0
Sure that is when you need to setup a proxy for your app:
Setting up a Proxy | Support Services Blog
It will handle the authentication for you and all will be good to go.
Even if it's not esri authentication? It's just simple web authentication, unrelated to esri's AGS/AGOL stuff. I've used the esri resource proxy before, but only on esri resources...
Oh, sorry I did not understand that the request was not going to ArcGIS Server. In that case you will need to get a proxy that pass basic authentication with your request or use
to add your request end point required info.
I looked for something to do this a while back and could not find anything.
Not sure what I would do in the setRequestPreCallback though.
There's a branch of ESRI's resource-proxy that supports HTTP Basic Authentication for non-ArcGIS Services:
GitHub - sverkerEsriSE/resource-proxy at add-support-for-basic-auth
I was able to get the .NET version working to connect to Oracle Service Cloud's REST API.
resource-proxy/README.md at add-support-for-basic-auth · sverkerEsriSE/resource-proxy · GitHub
If you want to use setRequestPrecallback function: Please find following samples
developer-support/web-js/Using-setRequestPreCallback-function at gh-pages · Esri/developer-support ·...
developer-support/web-js/setRequestPreCallback-Modify-Print-Lengend at gh-pages · Esri/developer-sup...
This function will intercept any request going out from your application and you can dynamically modify this request to pass what you need to pass.
Thanks Akshay. However, I'm still not sure how I would set up the authentication at that point.
I am not sure if you have figured this out but you should be able to send username and password before the request is send to the server. But in my opinion that is not the best way to do since your credentials are exposed.