Hello,
This problem is driving me crazy whole day :(
Here is my situation:
- I'm trying to get user list from REST API of my server (xxxxxxx:8087/im/1/rest/users)
- This call is secured with Basic authorization.
- When I run this simple code from JAVA console app, I receive correct XML with
no problems
public static void main(String[] args) throws IOException {
String url = "http://xxxxxxxxxxx:8087/im/1/rest/users";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Authorization", "Basic ZGVmYXVsdFxhZG1pbjpBZG1pbg==");
int responseCode = con.getResponseCode();
Map<String, List<String>> map = con.getHeaderFields();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
}
* However when I try to do the same within JavaScript I can't get
any results.
* I've tried so many approaches and frameworks (Plain JS, AngularJS, JQuery) always with same result - 401/Unauthorized + CORS.
I really don't know what else to try. IMHO I don't think its CORS problem, since I'm able to get results from console app. Also I'm behind corporate proxy, but this server is in local network.
Rather than code snippet(I've tried every possible approved method from here), I'd like to ask whether there could be some cause to this problem.
Recap of my observations:
* Call of GET method within JAVA console app - OK
* Call from SOAP-UI - OK
* Call from several FireFox add-ons (RESTClient, HttpRequester) - OK
* Call from local JS file - NOK
* Call from deployed JS page - NOK
Any suggestion is greatly appreciated.
Thanks in advance.