2016-12-12 16 views
0

我正在嘗試通過Team Foundation Server 2015 Rest API讀取查詢。下面的代碼工作在Internet Explorer中:Chrome中的TFS 2015 REST API身份驗證

var tasksURI = tfs_url + collection + '/' + project + '/_apis/wit/wiql/' + queryId; 


$.ajax({ 
    url: tasksURI, 
    type: 'GET', 
    contentType: "application/json", 
    accepts: "application/json", 
    cache: false, 
    dataType: 'json' 
    }).done(function (data) { 
    var items = []; 
    $.each(data.workItems, function (key, val) { 
    items.push("<li> <a href='" + val.url + "'>" + val.id + "</a></li>"); 
    }); 

    $("<ul/>", { 
    html: items.join("") 
    }).appendTo("body"); 

}); 

在Chrome中它產生以下錯誤消息:

Failed to load resource: the server responded with a status of 401 (Unauthorized) 

我看到這個其他問題: TFS 2015 REST API Authentication

但我仍然得到同樣的如果我遵循答案,錯誤。此外,我寧願提示用戶輸入憑據(如在IE中),而不是存儲它。

我在做什麼錯?

+0

您在哪裏設置Authorization標頭? – Legends

+0

你有沒有試過https://sysadminspot.com/windows/google-chrome-and-ntlm-auto-logon-using-windows-authentication/ –

+0

IE會提示用戶輸入腳本的憑證嗎? –

回答

0

我測試過你的腳本,IE和Chrome都有401問題,沒有授權標題。但是,如果將以下內容添加到腳本中,則IE和Chrome都在工作:

beforeSend: function (xhr) { 
    xhr.setRequestHeader("Authorization", "Basic " + btoa("username" + ":" + "password")); 
},