0
votes

I'm using OpenFire with the REST API plugin installed.

I'm attempting to get a list of chat rooms through an AngularJS $http call to http://localhost:9090/plugins/restapi/v1/chatrooms

with the proper Authorization header set in the $http.defaults.headers.common property.

When the call is made, I get the following error:

OPTIONS http://localhost:9090/plugins/restapi/v1/chatrooms 401 (Unauthorized)(anonymous function) @ angular.js:10722sendReq @ angular.js:10515serverRequest @ angular.js:10222processQueue @ angular.js:14745(anonymous function) @ angular.js:14761Scope.$eval @ angular.js:15989Scope.$digest @ angular.js:15800(anonymous function) @ angular.js:16028completeOutstandingRequest @ angular.js:5507(anonymous function) @ angular.js:5784


XMLHttpRequest cannot load  http://localhost:9090/plugins/restapi/v1/chatrooms. Response for preflight has invalid HTTP status code 401

The truly annoying issue is, that when I build the same request through Postman, it works perfectly and the expected response is received but inside the browser (whether through $http, or a call to window.fetch through the console) I keep getting that error.

Supposedly, the OpenFire REST API supports CORS (I went so far as to check the plugin source code), but nothing seems to help.

2

2 Answers

1
votes

I'm the developer of REST API plugin. You are right that the REST API supports CORS, and it is possible to call it directly from angular js. The mentioned problems (preflight request) will by done by your browser. I just fixed the issue that the OPTION request don't need to auth. Checkout the REST API version: 1.1.7

0
votes

I suggest you to compare the fiddler request and the browser request (headers + body). It should work if they are 100% identical..