【问题标题】:Getting CORS error in Http request using ionic4使用ionic4在Http请求中获取CORS错误
【发布时间】:2019-06-25 03:43:23
【问题描述】:

API 调用出错

ERROR => 从源“http://localhost:8101”访问“localhost:3003/graphql”处的 XMLHttpRequest 已被 CORS 策略阻止:跨源请求仅支持协议方案:http、data、chrome、chrome-extension ,https。

apollo: Apollo,
    httpLink: HttpLink
  ) {
    apollo.create({
      link: httpLink.create({ uri: 'localhost:3003/graphql}),
      cache: new InMemoryCache()
    });

为所有来源启用 CORS(节点 Api)

【问题讨论】:

    标签: ionic4


    【解决方案1】:

    由于错误指的是only supported for protocol schemes: http....,这当然意味着您刚刚忘记在代码中的请求中添加httpshttp

    所以请注意localhost:3003/graphql 必须更改为http://localhost:3003/graphqlhttps://localhost:3003/graphql

    apollo: Apollo,
        httpLink: HttpLink
      ) {
        apollo.create({
          link: httpLink.create({ uri: 'http://localhost:3003/graphql'}),
          cache: new InMemoryCache()
        });
    

    【讨论】:

      猜你喜欢
      • 2021-09-12
      • 2018-03-05
      • 2018-07-08
      • 1970-01-01
      • 2017-11-17
      • 2021-05-28
      • 1970-01-01
      • 1970-01-01
      • 2015-12-07
      相关资源
      最近更新 更多