【发布时间】:2017-01-09 20:36:58
【问题描述】:
我需要访问 http://www.wienerlinien.at/ogd_routing/XML_TRIP_REQUEST2?locationServerActive=1&type_origin=any&name_origin=60201095&type_destination=any&name_destination=60200769 (返回一个 XML 文件)
->这会导致跨域请求错误(不幸的是服务只能通过http获得)。
我还在我的服务器中启用了跨域。但是没有任何成功。
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();
}
}
});
});
这是执行http请求的函数:
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;
}
是否有任何解决 angularJS 中的交叉输入请求的食谱解决方案?或解决方法?
提前致谢, 沃尔夫冈
【问题讨论】:
-
当我尝试在服务器端启用 CORS 时,我唯一的经验与 Web Api 2 有关。这是一个有用的链接(假设 Web Api 适用于您的情况)-enable-cors.org/server_aspnet.html。