3

我一直在使用 CORS 代理来处理 http 请求,这对我来说很好。最近我遇到了一个发送电子邮件的 API(通过 https 请求),它需要 http 基本身份验证。我想知道如何实现这一点。

这是我使用的代理服务器: https ://github.com/gr2m/CORS-Proxy

并考虑到这个 https://github.com/Rob--W/cors-anywhere 这个支持 https 但没有基本身份验证。

4

1 回答 1

0

你看过MDN 的例子吗?这应该适合你恕我直言:

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(); 
  }

或者您也可以在每个请求上添加必要的请求标头(但这不应该是必要的恕我直言):

invocation.setRequestHeader('Authorization', btoa(unescape(encodeURIComponent(username + ":" + password)))); 
于 2013-10-20T21:19:22.693 回答