3

I am trying to access a webservice that has Windows authentication. I am basically using most of what is written on this page:

$.ajax({
    url: url,
    method: 'GET',
    async: true,
    data: {},
    dataType: 'json',
    crossDomain: true,
    xhrFields: {
        withCredentials: true
    },
    beforeSend: function(xhr) {
        // set authorization header
        xhr.setRequestHeader("Authorization", "Basic " + Base64.encode(username + ":" + password));
    },
    success: function(data){
                // success
    },
    error: function(request, status, error) {
        // handle problem
    }
});

I also defined the external hosts on the .plist file. My issue is that I always get an error. To make it worst, nothing comes out on the error function that is slightly useful (this output is from Firefox, to simplify):

Object { readyState=0, status=0, statusText="error"}

I also tried on the simulator, but instead of immediately giving me the error I think its timing out. What I have been seeing, and what I am using, is a request using Basic authentication. So is there a way to actually implement this using Windows authentication?

Rui Peres
  • 25,741
  • 9
  • 87
  • 137

2 Answers2

1

In the end what I did:

 $.ajax( {
                             url:webServiceLink,
                             method: "GET",
                             timeout:30000,
                             data: "{}",  
                             dataType: "xml",
                             beforeSend : function(req) {
                             req.setRequestHeader("Authorization", 
                                                  make_base_auth (username,password));                             
                             },
                             success: OnGetMemberSuccess,
                             error: OnGetMemberError
                             });
                      });

In the external hosts I putted: *.


Update 1.0: Stopped working again...

Update 2.0 Found the issue:

The base 64 encoding is accepting the following chars:

_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

If you put a login/password with something else, you will have problems. :)

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
  • that is strange, base64 should be able to encode almost anything, since it is used to encode binary data in ascii. But it does raise an interesting question. I have to try that. – Loïc Faure-Lacroix Jun 29 '12 at 19:53
  • If you're using window.btoa then that's right. But different encoders in pure js might be able to encode unicode strings. – Loïc Faure-Lacroix Jun 29 '12 at 19:59
0

may be you should have a look at Access-Control-Allow-Headers

Community
  • 1
  • 1
Julien C.
  • 946
  • 8
  • 22