HarmonyOS H5调用出现跨域问题?

H5调用出现跨域问题,日志错误:

Access to fetch at 'xxx' from origin 'xxx' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled."
阅读 516
1 个回答

还请参考下以下方法:

(1)可以使用web组件的loadData接口,用于加载指定的数据,该接口的参数baseUrl可以实现:入参baseUrl可以指定的一个URL路径("http"/"https"/"data"协议),并由Web组件赋值给window.origin。通过该接口更改协议可以解决跨域问题。

(2)通过customizeSchemes接口,isSupportCORS表示是否支持跨域请求。schemeName表示自定义协议名称。https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-webview-V5\#customizeschemes

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进