我試圖在瀏覽器堆棧上的Silverlight上對Web服務器執行跨域基本身份驗證,但我無權訪問計算機,但我無法訪問代碼或託管代碼。每當我嘗試下面的代碼,我收到了NotSupportedException
,跨域基本身份驗證
var httpClient = new HttpClient();
WebRequest.RegisterPrefix("http://", WebRequestCreator.BrowserHttp);
var byteArray = Encoding.UTF8.GetBytes("username:password");
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
var response = await httpClient.GetAsync("http://www.example.com", HttpCompletionOption.ResponseHeadersRead);
我也試圖與阿賈克斯以下,但它變成一個OPTIONS 1.1請求,
$.ajax({
type: "GET",
url: "http://www.example.com",
global: false,
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
},
});
如果我改變http://www.example.com
不爲跨域調用這兩個代碼示例工作。在這種情況下,是否有可能進行跨域的基本認證?