Error 401 (Unauthorized)

0

I have this code at the time of accessing the url marks me the error 401 (Unauthorized) apparently does not receive the user and password because to access the page I need to authenticate, since I am making a request where I entered the curp and you should throw me the person's data. Thanks

var usr = "xmalmorthen",
  pwd = "b16f550d147bf92e9455074d9edfe013",
  server = "http://" + usr + ":" + pwd + "@wsrenapo.col.gob.mx/curp2",
  service = "CURP",
  method = "getInfo",
  call = server + "/" + service + "/" + method + "/" + CURP;                            

var jqxhr = $.get(call, function(data) {
  console.log (data);
  app.MsgBox("Correcto");
}, "json")
.fail(function() {              
  app.MsgBox("Ocurrió un error al intentar conectar con el servidor...");               
});
    
asked by Raymundo 26.05.2018 в 05:54
source

1 answer

0

Depending on the version of jQuery that you are using basic authentication with http is sending the username and password as follows:

var usr = "xmalmorthen",
  pwd = "b16f550d147bf92e9455074d9edfe013",
  server = "http://wsrenapo.col.gob.mx/curp2",
  service = "CURP",
  method = "getInfo",
  call = server + "/" + service + "/" + method + "/" + curl;                            

var jqxhr = $.ajax({url: call, username: usr, password: pwd, method: 'GET'}, function(data) {
  console.log (data);
}, "json")
.fail(function() {              
  alert("Ocurrió un error al intentar conectar con el servidor...");               
});

When this happens it is always good to resort to the official documentation. where it indicates how to send 'password' and 'username'

Change $ .get to $ .ajax because it always expresses things better when it is done more than a GET (this is a GET with simple authentication).

    
answered by 26.05.2018 в 10:22