0
下面是我的发送请求功能:通过类似的东西直接无法发送授权头使用Ajax
function invokeService() {
$(document).ready(function() {
var user = "User1";
var pass = "Pwd1";
var hash_str=make_base_auth(user, pass);
// the post to your webservice or page
$.ajax({
method: "GET",
xhrFields: {
withCredentials: true
},
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', hash_str);
},
headers: {
'Authorization': 'Basic ' + hash_str
},
url: "http://Servername/ProjName/TestService.svc/GetDetails/" + $('#itemid').val(),
contentType: "application/json; charset=utf-8",
dataType: "jsonp"
});
});
}
我已经尝试不同的方法,通过将用户名和密码:
$.ajax({
method: "GET",
username: user,
password: pass,
...
});
并通过设置授权标题,但每一个领带我检查它在提琴手,Auth
部分请求它声明“没有授权headerr存在”。它只是不发送它。任何人都可以帮我修复我的授权标题吗?
下面是什么提琴手的请求头显示出来:
GET /projName/TestService.svc/GetDetails/ABC123?callback=jsonpxxxxxxxxxxxxx HTTP/1.1
Client
Accept: application/javascript, */*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Transport
Connection: Keep-Alive
Host: ServerName
它不是编码是问题,它只是头不发送 – ElenaDBA
我明白了,但我记得有同样的问题,当我试图发送用户身份验证与你一样的方式。 –