cancel
Showing results for 
Search instead for 
Did you mean: 

How to login to rest services with javascript

ismail_codar
Champ in-the-making
Champ in-the-making
I'am using jquery. I can not run the following code.
Returns 405 Method Not Allowed http error.
If you remove line of the contentType: "application/json; charset=utf-8"  returns 415 Unsupported Media Type.

<html>
<head>
   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
   <script type="text/javascript">
   $(document).ready(function(){
   
   $.ajax({
     type: "POST",
     url: "http://localhost:8080/activiti-rest/service/login",
     dataType: "json",
     contentType: "application/json; charset=utf-8",
     data: {
      "userId": "kermit",
      "password": "kermit"
      },
     success: function(json) {
      alert(json.success);
      }
   });

   });
   </script>
</head>
<body>
</body>
</html>
3 REPLIES 3

frederikherema1
Star Contributor
Star Contributor
All REST-requests are secured with BASIC Http authentication. A bit strange, but to use the REST-login, you should set the username and password on your JQuery request. If successfull, JSON will be returned. If not Not Allowed (or Unauthorized) will be the response…

mak10
Champ in-the-making
Champ in-the-making
I am facing the same issue with activiti 5.9. Did you finally find out how to get this working?

mak10
Champ in-the-making
Champ in-the-making
Got it working - was a problem with quotes.

https://gist.github.com/2464057