user3061516
user3061516

Reputation: 115

Consumption webservice rest returns: No 'Access-Control-Allow-Origin'

I have a problem to consume a third-party web service, when trying to consume the same by the JavaScript the return I get is:

XMLHttpRequest cannot load http://xxxxxxxxx:yyyyy/sccwebclient/svc/filetransfers/?startedDay%3E2018-05-02T00%3A00%3A00. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

but when trying to consume the same by the postman I can get a desired response, which is Json, to consume the same it is necessary to pass a header a login and password, as follows:

Authorization: xxxx #base64Code

to consume the webservise I created the following script:

function getListaWebService(url){
                $.ajax({
                    'url': url,
                    Type: "GET",
                    dataType: "json",
                    headers: {
                        "Authorization": "xxxx " + geraBase64("xxxx", "yyyy")
                    }
                }).done(function (objJson){
                    console.log("objJson", objJson);
                }).error(function (err) {
                    console.log("err", err);
                }); 
}

what I did wrong, if it is cross domain problem, how can I solve it by JS or Java?

Upvotes: 0

Views: 121

Answers (1)

user1510154
user1510154

Reputation:

This is a CORS issue. You can read about it here. You either have to ask your third party API server to allow your domain to access their resource in the Access-Control-Allow-Origin response header or another approach is to go with JsonP - read about it here

Upvotes: 1

Related Questions