简体   繁体   中英

How to make a cors proxy server process https request with http basic authentication?

I've been using a CORS-Proxy for http requests, which is just fine for me. Recently I came across an API for sending emails (by https requests), that requires http basic authentication. I am wondering how to implement this.

this is the proxy server i use: https://github.com/gr2m/CORS-Proxy

and considering this https://github.com/Rob--W/cors-anywhere this one support https but no basic authentication.

Have you looked at the MDN example ? This should work for you imho:

var invocation = new XMLHttpRequest();
var url = 'http://bar.other/resources/credentialed-content/';

function callOtherDomain(){
  if(invocation) {
    invocation.open('GET', url, true);
    invocation.withCredentials = true;
    invocation.onreadystatechange = handler;
    invocation.send(); 
  }

Or you could also add the necessary request header on every request (but this shouldn't be necessary imho):

invocation.setRequestHeader('Authorization', btoa(unescape(encodeURIComponent(username + ":" + password)))); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM