0

I want to use Authorization and Basic to provide credentials. How do I provide these parameters in the fetch() function?

<script>
    

    fetch('http://localhost:8080/o/headless-delivery/v1.0/sites/20121/blog-postings/', {Authorization:"Basic "+btoa('test@corporation.com:test') })
    .then((Response) => console.log(Response))
</script>

When I load the html page, I am getting an 403 error code in the console. Am I providing the parameters properly? What might be the problem?

I am expecting a JSON as a response.

John117
  • 31
  • 5
  • 1
    Is this https://stackoverflow.com/questions/43842793/basic-authentication-with-fetch answers your question? – RAllen Feb 06 '23 at 05:06
  • It's just a simple typo... headers go under the `headers` key... `fetch(url, { headers: { Authorization: \`Basic ${btoa('test@corporation.com:test')}\` }})` – Phil Feb 06 '23 at 05:07

0 Answers0