I am trying to send an auth request to a servlet hosted by glassfish server 4, receiving back a message in plain text.
The servlet is configured for a BASIC authentication with CONFIDENTIAL transport (https) (The authentication and the servlet answer work by visiting the page with a web browser)
Here is the jquery script using ajax:
$.ajax
({
type: "GET",
url: "https://192.168.146.128:8181/path_to_servlet",
dataType: 'text',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
},
async: false,
success: function (data){
alert(data);
}
});
and the servlet code:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text");
PrintWriter out = response.getWriter();
out.println("hello");
out.close();
}
The problem is that the request don't get any answer of any type (tryied on IE, chrome and firefox with the same result).
What should I do? Is this the right way to authenticate? And do I need to send the header authorization request with every further request?