1

How can I get data from web server with http authentication in phonegap ap? I tried (use Dom 7):

$$.ajax({
  url: 'http://@api.mysite.com/api/json',
  method: 'GET',
  dataType: 'json',
  xhrFields: { withCredentials: true },
  beforeSend: function (xhr){
    xhr.setRequestHeader('Authorization', 'Basic ' + btoa(username + ":" + password));
  },
  success: function (data, status, xhr) {
    console.log(arguments);
  },
  error: function (xhr, status) {
    console.log(arguments);
  }
})

and

$$.ajax({
  url: 'http://' + username + ':' + password + '@api.mysite.com/api/json',
  method: 'GET',
  dataType: 'json',
  xhrFields: { withCredentials: true },
  success: function (data, status, xhr) {
    console.log(arguments);
  },
  error: function (xhr, status) {
    console.log(arguments);
  }
})

but i have statusCode = 401 in response.

user2987203
  • 11
  • 1
  • 3

0 Answers0