ajax - jquery basic authentication failing -


consider header info:

 accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8  accept-encoding:gzip, deflate, sdch  accept-language:en-us,en;q=0.8  authorization:basic twluzvn0yxi6twluzvn0yxi=  cache-control:max-age=0  connection:keep-alive  host:* 

this header info url. trying json value url. url, when accessed alone pops username , password.

try1:

      $.ajax({         type:'get',       url: 'http://'+domainname+':9898/*/*',       datatype:"json",       username: '*',       password: '*',       async: false       }).responsetext; 

try2

      $.ajax({         type:'get',       url: 'http://'+domainname+':9898/jolokia/*/*',       datatype:"json",       crossdomain: true,       beforesend: function(xhr) {            xhr.setrequestheader("authorization", "basic " + btoa('*' + ":" + '*'));            },       async: false       }).responsetext; 

try3:

tried adding in web.xml of tomcat.

<filter> <filter-name>corsfilter</filter-name> <filter-class>org.apache.catalina.filters.corsfilter</filter-class> <init-param>  <param-name>cors.allowed.origins</param-name> <param-value>*</param-value> </init-param> <init-param> <param-name>cors.allowed.methods</param-name> <param-value>get,post,head,options,put</param-value> </init-param> <init-param>  <param-name>cors.allowed.headers</param-name>  <param-value>content-type,x-requested-with,accept,origin,access-control-request-    method,access-control-request-headers</param-value>  </init-param>  <init-param>  <param-name>cors.exposed.headers</param-name>  <param-value>access-control-allow-origin,access-control-allow-credentials</param-    value>  </init-param>  <init-param>    <param-name>cors.support.credentials</param-name>  <param-value>true</param-value>  </init-param>  <init-param>    <param-name>cors.preflight.maxage</param-name>    <param-value>10</param-value>   </init-param> </filter> <filter-mapping>   <filter-name>corsfilter</filter-name>   <url-pattern>/*</url-pattern> </filter-mapping> 

but still not able access url, still gives following error:

     http://***.**.**.**:9898/*/* 401 (unauthorized)     jquery.min.js:5 xmlhttprequest cannot load http://**.**.**.**:9898/*/*. no 'access-control-allow-origin' header present on requested resource. origin http://localhost:8080 therefore not allowed access. response had http status code 401.(index):1 uncaught syntaxerror: unexpected token u 

i need access url , json values url. url protected username , password , know.

i don't how can cross domain issue. when remove authentication url code works fine:

      $.ajax({         type:'get',       url: 'http://'+domainname+':9898/*/*',       datatype:"json",       async: false       }).responsetext; 

but authenticate url code fails, after applying above steps too, code fails.

try setting additional jquery ajax parameter:

xhrfields: { withcredentials: true }

this enable cors functionality.


Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -