调用REST API时Access-Control-Allow-Origin的问题

问题描述 投票:0回答:1

使用公司网络调用REST API但始终面临“Access-Control-Allow-Origin”问题。请在下面找到proxy.config.js以启用CORS。我正在使用样本每日天气报告API来生成折线图。请在下面找到API。我也附上了截图,请你帮我解决这个问题。

https://samples.openweathermap.org/data/2.5/forecast/daily?id=524901&appid=b1b15e88fa797225412429c1c50c122a1

var HttpsProxyAgent = require('https-proxy-agent');
var proxyConfig = [{
  context: '/',
  target: 'https://samples.openweathermap.org',
  secure: false
}];

function setupForCorporateProxy(proxyConfig) {
  var proxyServer = process.env.http_proxy || process.env.HTTP_PROXY;
  if (proxyServer) {
    var agent = new HttpsProxyAgent(proxyServer);
    console.log('Using corporate proxy server: ' + proxyServer);
    proxyConfig.forEach(function(entry) {
      entry.agent = agent;
    });
  }
  return proxyConfig;
}

module.exports = setupForCorporateProxy(proxyConfig);

enter image description here

angular rest
1个回答
-1
投票

激活您的CORS插件以避免Access-Control-Allow-Origin错误

© www.soinside.com 2019 - 2024. All rights reserved.