0
I am now starting to use authentication in Datasnap.
I am trying to access the methods via AJAX and is returning error 401 - Unauthorized.
My request is as follows:
$.ajax({
username: login,
password: pass,
async : false,
cache: "false",
dataType: 'json',
type: 'get',
url: url,
success: function(data){...}
I did it following this question, where the only difference is that I’m not using jsonp
.
When accessed by browser, a box is displayed for entering the user and password, when I enter the credentials allows me to continue.
Does anyone know how to solve?
EDIT 1
I have also tried to make the request using:
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', makeBaseAuth(login, pass));
}
In place of username
and password
.
Which Datasnap you are using and how you created the Datasnap project to start working as Webservice, was from the Datasnap REST or Datasnap Server?
– Jefferson Rudolf
@Jeffersonrudolf I’m using Delphi XE7, it was created as Datasnao REST, and I marked the Authentication option when creating it. I have already introduced the Onauthentication method and the Userroles. Testing in the browser or Serverfunctioninvoker works perfectly.
– henrique romao
In your Datasnap you already have the get function ready?... because to access the functions of Datasnap has a nomenclature, for example: IP:port/datasnap/Rest/Tservermethods1/method of your function in the datasnap, because when you fill user and password and enter, you will require this function to be able to validate, otherwise it will give problem with communication.
– Jefferson Rudolf
@Jeffersonrudolf Yes, as I said in the question, if testing the URL directly from the browser works normally. I have other Datasnaps that work with AJAX normally, but do not use authentication
– henrique romao
You pass the user and password to the Datasnap and want the same authentication and return if everything went all right?... If that is so, you will start working with headers that are the headers, you send user and password so Datasnap can authenticate. You use some application to be able to do the requisition tests, if you do not use, I suggest you use Postman which is very good for testing.
– Jefferson Rudolf
@Jeffersonrudolf I edited the question by adding an example of something else I tried.
– henrique romao