Basic authentication with fetch?
You are missing a space between Basic
and the encoded username and password.
headers.set('Authorization', 'Basic ' + base64.encode(username + ":" + password));
Basic authentication using Fetch API in JS
Setting the mode tomode: "no-cors"
"no-cors"
causes any attempt to do something that requires CORS permission to silently fail (instead of throwing an exception).Setting Authorization
and Content-Type
headers (although setting a Content-Type
on a GET request, which can't have content in the first place, doesn't make sense) requires CORS permission.
Given that the request requires an API key, and that to use it client-side you would have to distribute your API key to all your users, there is a high probability that the service is not designed to be access directly by web browsers (so you should use server-side code instead).
Related Topics
Jsf/Primefaces Ajax Updates Breaks Jquery Event Listener Function Bindings
How to Send Authorization Header with Axios
Regular Expression Not Working for at Least One European Character
React 18, Useeffect Is Getting Called Two Times on Mount
How to Use Jquery to Style /Parts/ of All Instances of a Specific Word
Regular Expression to Match A, Ab, Abc, But Not Ac. ("Starts With")
Why Does ('0' ? 'A':'B') Behave Different Than ('0' == True ? 'A':'B')
JavaScript Closure Not Working
Why Is 'Event' Variable Available Even When Not Passed as a Parameter
C# Web Method Is Not Calling in JavaScript
JavaScript Array .Reduce with Async/Await
How Does Trello Access the User's Clipboard
Does It Make Sense to Use Require.Js with Angular.Js
Differencebetween JavaScript and Ecmascript
Can Jquery Read/Write Cookies to a Browser