簡體   English   中英

如何使用http基本身份驗證使cors代理服務器處理https請求?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM