[英]How to make a cors proxy server process https request with http basic authentication?
我一直在使用CORS-Proxy来处理http请求,这对我来说很好。 最近我遇到了一个用于发送电子邮件的API(通过https请求),这需要http基本身份验证。 我想知道如何实现这一点。
这是我使用的代理服务器: https : //github.com/gr2m/CORS-Proxy
并考虑到这个https://github.com/Rob--W/cors-any这个支持https但没有基本身份验证。
你看过MDN的例子了吗? 这应该适合你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();
}
或者您也可以在每个请求上添加必要的请求标头(但这不是必需的):
invocation.setRequestHeader('Authorization', btoa(unescape(encodeURIComponent(username + ":" + password))));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.