0

I need to access http://www.wienerlinien.at/ogd_routing/XML_TRIP_REQUEST2?locationServerActive=1&type_origin=any&name_origin=60201095&type_destination=any&name_destination=60200769 (returns an XML file)

->This causes a cross origin request Error (unfortunately service is only available via http).

I also enabled cross-origin in my server. Howevery without any success.

gulp.task('browser-sync', function () {
    browserSync({
        notify: true,
        port: 8000,
        server: {
            baseDir: "dist",
            middleware: function (req, res, next) {
                res.setHeader("Access-Control-Allow-Origin", "*");
                next();
            }
        }
    });
});

This is the function which performs the http request:

  this.requestjourney = function (id1, id2) {
        
        var promise = $http({
            method: 'GET',
            timeout: 5000000,
            // url: "http://www.wienerlinien.at/ogd_routing/XML_TRIP_REQUEST2?locationServerActive=1&outputFormat=JSON&type_origin=any&name_origin=Reumannplatz&type_destination=any&name_destination=Stephansplatz", 
            url: "http://www.wienerlinien.at/ogd_routing/XML_TRIP_REQUEST2?locationServerActive=1&type_origin=any&name_origin=" + id1 + "&type_destination=any&name_destination=" + id2,             
            locationServerActive: 1,
            excludedMeans: 0,
            excludedMeans: 1,
            excludedMeans: 3,
            excludedMeans: 4,
            excludedMeans: 5,
            excludedMeans: 6,
            excludedMeans: 7,
            excludedMeans: 8,
            excludedMeans: 9,
            excludedMeans: 10,
            excludedMeans: 11,
            contentType: 'application/x-www-form-urlencoded; charset=utf-8'
        });

        return promise;
    }

Is there any kind of cook book solution fixing cross oringin request in angularJS? Or Workaround ?

Thanks in advance, Wolfgang

1
  • My only experience is related to Web Api 2 when attempting to enable CORS on the server side. Here's a helpful link (assuming that Web Api is applicable in your case) - enable-cors.org/server_aspnet.html . Commented Sep 1, 2016 at 20:37

1 Answer 1

1

Are you sure that CORS is enabled on server side? When I request the URL from my web page, I don't get an "Access-Control-Allow-Origin" header back. (And Firefox complains about the missing header in the developer console.) This header is the minimum requirement for things to work.

Read more here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests

And in case of doubt, try with jQuery instead of Angular first, e.g. with $.get(url).

Sign up to request clarification or add additional context in comments.

1 Comment

I tried jQuery, unfortunately this does not solve the problem. XMLHttpRequest cannot load wienerlinien.at/ogd_routing/……in=any&name_origin=60201095&type_destination=any&name_destination=60200769. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:8000' is therefore not allowed access.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.