我正在进行网络API授权
我使用以下代码
从jquery到Web API进行授权调用<script src="Scripts/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(){
var ulEmployees = $('#ulEmployee');
var username = $('#uname').val();
var password = $('#pword').val();
username = "male";
password = "male";
$('#btn').click(function () {
$.ajax({
type: 'GET',
url: 'api/Employees',
dataType: 'json',
headers: {
'Authorization': 'Basic' + btoa(username + ':' + password)
},
success: function (data)
{
ulEmployees.empty();
$.each(data, function (index, val) {
var fullName = val.FirstName + ''+val.gender + '' + val.LastName;
ulEmployees.append('<li>' + fullName + '</li>');
});
},
});
});
$('#btnclear').click(function(){
ulEmployees.empty();
});
});
});
</script>
但在控制器方面,我没有正确接收数据
如下:
actionContext.Request.Headers.Authorization.Parameter =空
actionContext.Request.Headers.Authorization.Scheme =&#34; BasicbWFsZTptYWxl&#34;
但我确实需要如下所示
actionContext.Request.Headers.Authorization.Parameter =&#34; bWFsZTptYWxl&#34;
actionContext.Request.Headers.Authorization.Scheme =&#34;具有基本&#34;
答案 0 :(得分:2)
看起来您需要在
中的“基本”后附加一个空格符号CONTAINSTABLE(<Table A>, <TargetColumn>, '"0110001*"')
所以这个字符串可能看起来像
'Authorization': 'Basic' + btoa(username + ':' + password)