【问题标题】:How to make a cors proxy server process https request with http basic authentication?如何使用 http 基本身份验证使 cors 代理服务器处理 https 请求?
【发布时间】:2013-10-06 12:32:24
【问题描述】:

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

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

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

【问题讨论】:

标签: javascript https proxy cors


【解决方案1】:

你看过MDN example吗?这应该对你有用:

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

【讨论】:

  • 感谢您的回复。看来我没有说清楚。我需要的基本上是一个可以处理 http 加 https 请求的代理服务器。最好的部分是,它适用于节点 js。有了它,我可以通过将地址添加到服务器的url来通过代理服务器调用任何url,并访问代理服务器而不是原始网站。
  • @Newset 那么您希望 HTTP 基本身份验证的凭据仅由代理服务器使用吗?不知道这是否可能,对不起。
猜你喜欢
  • 1970-01-01
  • 2016-04-24
  • 2012-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-26
相关资源
最近更新 更多