简体   繁体   English

如何使用http基本身份验证使cors代理服务器处理https请求?

[英]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. 我一直在使用CORS-Proxy来处理http请求,这对我来说很好。 Recently I came across an API for sending emails (by https requests), that requires http basic authentication. 最近我遇到了一个用于发送电子邮件的API(通过https请求),这需要http基本身份验证。 I am wondering how to implement this. 我想知道如何实现这一点。

this is the proxy server i use: https://github.com/gr2m/CORS-Proxy 这是我使用的代理服务器: https//github.com/gr2m/CORS-Proxy

and considering this https://github.com/Rob--W/cors-anywhere this one support https but no basic authentication. 并考虑到这个https://github.com/Rob--W/cors-any这个支持https但没有基本身份验证。

Have you looked at the MDN example ? 你看过MDN的例子了吗? This should work for you imho: 这应该适合你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)))); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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