fetch get authorization header 1

fetch get authorization header

fetch('URL_GOES_HERE', { 
   method: 'post', 
   headers: new Headers({
     'Authorization': 'Basic '+btoa('username:password'), 
     'Content-Type': 'application/x-www-form-urlencoded'
   }), 
   body: 'A=1&B=2'
 });

Here is what the above code is Doing:
1. We’re using the fetch API to make a POST request to the URL.
2. We’re setting the Authorization header to the value of ‘Basic ‘+btoa(‘username:password’).
3. We’re setting the Content-Type header to the value of ‘application/x-www-form-urlencoded’.
4. We’re setting the body of the request to the value of ‘A=1&B=2’.

Similar Posts