views:

232

answers:

1

First, I'm working in Google Chrome, if that helps. Here is the behavior:

I send an xhr request via jQuery to a remote site (this is a chrome Extension, and I've set all of the cross-site settings...):

$.ajax({
    type: "POST",
    contentType : "text/xml",
    url: some_url,
    data: some_xml,
    username: user,
    password: pass,
    success: function(data,status,xhr){
        alert(data);
    },
    error: function(xhr, status, error){
        alert(xhr.status);
    }
});

The URL that is being set returns a 302 (this is expected), and Chrome follows the redirect (also expected).

The new URL returns a prompt for credentials, which are not being pulled from the original request, so Chrome shows a login dialog. If I put in the original credentials, I get back a response about invalid request sent (it's a valid HTTP request -- 200 -- the remote server just doesn't like one of the headers).

When viewing the developer window in Chrome, there are two requests sent. The first is to the original URL with all settings set in the AJAX request. The second is to the redirect URL, with a method of "GET", nothing from the "POST" field, and no credentials.

I am at a loss as to what I can do. I either need to:

  1. Get the redirect URL so I can send a second request (xhr.getResponseHeader("Location") does NOT work),

  2. Have the new redirect request preserver the settings from the original request, or

  3. Get the final URL that the error came from so I can send another request.

Ideally I don't want the user to have to put in their credentials a second time in this dialog box, but I'll take what I can get if I can just get the final URL.

A: 

Unfortunately there is no way to prevent xhr from auto-following redirects or set credentials for the redirect destination (it would be rather insecure anyway since that would allow the first site to redirect the credentials to any site, not only the one you want to get them).

ThiefMaster
Except, it will only redirect if the new URL meets the same origin policy. So is there a way to get the URL after the fact?
Anthony