Authentication headers are not sending JQuery Ajax

后端 未结 4 2148
粉色の甜心
粉色の甜心 2021-01-06 21:52

I have web server hosted in Apache Tomcat 7 with Basic authentication. I have Tomcat user \'tomcat\' with role \'tomcat\' and password \'tomcat\'. Following are my web.xml f

4条回答
  •  盖世英雄少女心
    2021-01-06 22:07

    mccannf got us 99% of the way there with a similar issue hover we switched up how we set the withCredentials property and this worked for us. notice we set the xhrFields property. This can been seen within the jQuery documentation for the ajax method here; http://api.jquery.com/jQuery.ajax/

    $.ajax({
        type: "GET",
        xhrFields: { withCredentials: true }, 
        beforeSend: function (request)
        {
            request.setRequestHeader("Authorization", "Basic  dG9tY2F0OnRvbWNhdA==");
        },
        url: "http://localhost:1222/testservice/rest/test/users",
        dataType:"jsonp",
        succes: function(res) {
            alert(ers); 
        },
        error: function(err) {
            alert(err);
        }
    });
    

    However, we were not using jsonp, simple json.

提交回复
热议问题