Cant retrieve an XML list from a web service

English! place to talk about development, programming and coding
Post Reply
Juanchotalarga
Znuny newbie
Posts: 1
Joined: 02 May 2018, 16:17
Znuny Version: 5 ITMS
Real Name: Juan
Company: none

Cant retrieve an XML list from a web service

Post by Juanchotalarga »

I have a server running OTRS 5 and I would like to retrieve a list in XML format. I'm running a JavaScript code that should display the list, but instead I get an error.

My local server is https://labcentos3/otrs/mds.pl?Action=ServiceList.
I think its a Perl script that runs on the server side and then displays a list in XML format.

This is what I get if I browse the local link, it gives me the list I want
https://i.stack.imgur.com/aXFUH.jpg
Image


I made and Html and JS file to try to do the same for working with the retrieved data later, but i cant get past and error.

HTML CODE:

Code: Select all

<html>
    <head>
        <title>XML read</title>
        <script src="reader.js" type="text/javascript"></script>
    </head>
    <body>
        <h1>XML File</h1><br/>
    </body>
</html>  
JS CODE

Code: Select all

var user = "bla bla bla";
var pass = "bla bla bla";



var getXMLFile = function(path, callback) {
    var request = new XMLHttpRequest();
    request.open("POST", path);
    request.setRequestHeader("Content-Type", "text/plain");
    //request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    request.setRequestHeader('Authorization', 'Basic ' + btoa(user + ":" + pass));
    request.onreadystatechange = function() {
        if(request.readyState === 4 && request.status === 200) {
            callback(request.responseXML);
        }    
    };
    request.send();
};

getXMLFile("https://labcentos3/otrs/mds.pl?Action=ServiceList", function(xml) {
   console.log(xml); 
});

And finally the error i get in Chrome Console is this:

XMLHttpRequest cannot load https://labcentos3/otrs/mds.pl?Action=ServiceList. The request was redirected to 'https://labcentos3/otrs/index.pl', which is disallowed for cross-origin requests that require preflight.
Post Reply