Sending jquery ajax authentication request to glassfish server fails -


i trying send auth request servlet hosted glassfish server 4, receiving message in plain text.

the servlet configured basic authentication confidential transport (https) (the authentication , servlet answer work visiting page web browser)

here 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 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 request don't answer of type (tryied on ie, chrome , firefox same result).

what should do? right way authenticate? , need send header authorization request every further request?

the jquery .ajax object allows "username" , "password" properties, don't try hard-code authorization header.

per http spec, send request data, if secured access denied response, reply authorization header.

if doesn't work when access manually server misconfigured sending client access-control-allow-headers header doesn't have authorization header allowed. if works when doing manually (not using ajax) it's cross domain issue, perhaps check error console or dev tools of browser using check request's response or warning/errors thrown.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -