Ayude a probar un problema CORS en Firefox jQuery ajax cuando 401
Esto me está volviendo loco.
jQuery 1.4.2, Windows XP sp3
Aquí está mi prueba.
Cargue Firefox 3.5+
http://plungjan.name/test/testcors.html
trabajos
Guarde el archivo en el disco duro y ejecútelo desde allí
Desde mi oficina lo externo funciona y lo interno no
Lo que también es interesante es que no puedo ejecutar ambos de una vez.
Antecedentes: hago unOBTENER a un servicio web interno que usaCORS. Por favor, hazloNO publicar cualquier respuesta sobre FF que no maneja solicitudes de dominio cruzado cuando lo hace desde v3.5 como se detallaaquí yaquí
Funciona en IE8 y FF3.6.6 de un servidor a otro y ahora casi desde el sistema de archivos (archivo: ///) al servicio.Solamente del sistema de archivos ysolamente cuando FF 3.6.6 necesita negociar(¡el usuario ya ha iniciado sesión, está autorizado y envía las credenciales!) ¿No obtengo los datos después de la negociación? jQuery xhr devuelve el estado 0 y no hay datos / texto de respuesta o lo que sea que me parezca, jQuery reacciona y guarda el xhr del 401 en lugar del 200 OK más tarde
Aquí está el resultado que obtengo al final de la comunicación cuando alerta al objeto XHR:
Status:success
Data:[]
XHR:
some native functions,
readyState:4
status:0
responseXML:null
responseText:
withCredentials:true
si hago una llamada al mismo servidor pero sin necesidad de credenciales, los datos se devuelven muy bien entre dominios
Entonces la comunicación es la siguiente:
GET /restapplicationusingcors/authenticationneeded-internal/someid
Accept: application/json
Accept-Language: en
.
.
Origin: null
Cookie: LtpaToken=...
el regreso es
HTTP/1.1 401 Unauthorized
Server: Apache
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 01:00:00 CET
WWW-Authenticate: Negotiate
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
Entonces FF envía
GET /restapplicationusingcors/authenticationneeded-internal/someid HTTP/1.1
Host: myhost.myintranet.bla
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6
Accept: application/json
Accept-Language: en
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Origin: null
Cookie: LtpaToken=....
Authorization: Negotiate ....
y es recompensado con el archivo que necesito, pero no puedo acceder a FF:
HTTP/1.1 200 OK
Date: Tue, 20 Jul 2010 12:08:39 GMT
Pragma: No-cache
Cache-Control: no-cache, max-age=600, s-maxage=3600
Expires: Thu, 01 Jan 1970 01:00:00 CET
X-Powered-By: ...
Content-Disposition: inline;filename=nnnnnn.json
Content-Language: en
Access-Control-Allow-Origin: ...
Keep-Alive: timeout=6, max=70
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/json;charset=UTF-8
LOS DATOS ENVIADOS DEL SERVIDOR SONNO EN EL OBJETO XHR
Aqui esta mi codigo
function getJSON(url,func,lang) {
accept = 'application/json';
lang=lang?lang:"*";
// gruesome hack to handle that APPENDS the mime header to */* !!!
// NOW HANDLED by first setting Accept to "" !!!
// if ($.browser.msie && url.indexOf('serveAsMime')==-1) {
// url+= '?serveAsMime='+accept;
// }
if (currentRequest != null) currentRequest.abort();
var requestObjectJSON = {
url : url,
// dataType: "json",
method : 'get',
beforeSend: function(xhr){
xhr.setRequestHeader('Accept', ""); // IE hack
xhr.setRequestHeader('Accept', accept);
xhr.setRequestHeader('Accept-Language', lang);
if (url.indexOf('-internal') !=-1) {
try {
xhr.withCredentials = true;
alert('set credentials')
}
catch(e) {
alert('cannot set xhr with credentials')
}
}
},
success: function(data,status,xhr) {
var responseText = xhr.responseText;
var responseJSON = xhr.responseJSON;
var t = "";
try{
for (var o in xhr) t += '\n'+o+':'+xhr[o];
}
catch(e) {
if (e.message.indexOf('.channel')==-1)alert(e.message);
}
alert('Status:'+status+'\nData:['+data+']\nXHR:'+t);
func(responseText);
},
}
currentRequest = $.ajax(requestObjectJSON);
}