当前位置:网站首页>[step on the pit series] H5 cross domain problem of uniapp
[step on the pit series] H5 cross domain problem of uniapp
2022-07-07 08:08:00 【The sea of waves】
List of articles
【 Step on the pit series 】uniapp And h5 Cross domain issues
Preface
Debug the mobile interface on the browser , appear Multiple... Are not allowed ‘Access-Control-Allow-Origin’ CORS Header information . And see Response Information returned , It is thought that there are many configurations on the server Settings for cross domain access , The problem caused by , So I've been looking for problems on the back end , After spending some time checking , Multiple cross domain access settings are not configured , And the real machine of the mobile terminal can be accessed normally , This has reversed the idea of investigation , Solve the problem from the front end .
What is cross-domain
Cross domain is a browser specific concept , finger js The code accesses sites other than its own source site . such as A In the web page of the site js Code , Request the B Site data , It's cross domain .
A and B To be considered a homogeneous domain , Then there must be the same agreement ( such as http and https No way. )、 Same domain name 、 And the same port number (port).
If you are doing App、 Small program, etc H5 platform , It does not involve cross domain issues .
How to solve
Solution :uni-app The official recommendation Use HBuilderX Browser built in
Go preview , There will be no cross domain issues in built-in browsers ; But if it is Chrome This cross domain problem will appear when previewing in browser , Official recommendation install Allow-Control-Allow-Origin: * plug-in unit
The way to solve . Reference resources :uni-app H5 Cross domain problem solution (CORS、Cross-Origin).
# Whether cross domain access is allowed CORS, If allowed , Set allowed domain names
accessControlAllowOrigin: '*'
# When cross domain access is allowed CORS, Methods and request headers that can be retrieved and returned
accessControlAllowMethods: GET, POST, OPTIONS
accessControlAllowHeaders: content-type, x-requested-with, x-ajax, x-token, x-remember
accessControlExposeHeaders: x-remember
Reference article
uni-app H5 Cross domain problem solution (CORS、Cross-Origin)
边栏推荐
- 快速使用 Jacoco 代码覆盖率统计
- Recursive construction of maximum binary tree
- json 数据展平pd.json_normalize
- 2022年茶艺师(中级)考试试题及模拟考试
- Network learning (III) -- highly concurrent socket programming (epoll)
- Complex network modeling (I)
- ROS Bridge 笔记(05)— carla_ackermann_control 功能包(将Ackermann messages 转化为 CarlaEgoVehicleControl 消息)
- ZCMU--1492: Problem D(C语言)
- 复杂网络建模(一)
- [quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
猜你喜欢
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
数据库实时同步利器——CDC(变化数据捕获技术)
2022 welder (elementary) judgment questions and online simulation examination
mysql多列索引(组合索引)特点和使用场景
Network learning (II) -- Introduction to socket
uniapp 移动端强制更新功能
Force buckle 145 Binary Tree Postorder Traversal
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
Real time monitoring of dog walking and rope pulling AI recognition helps smart city
互动送书-《Oracle DBA工作笔记》签名版
随机推荐
Linux server development, MySQL transaction principle analysis
Explore dry goods! Apifox construction ideas
【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
2022制冷与空调设备运行操作复训题库及答案
[UVM practice] Chapter 2: a simple UVM verification platform (2) only driver verification platform
2022年茶艺师(中级)考试试题及模拟考试
Linux server development, MySQL cache strategy
Force buckle 144 Preorder traversal of binary tree
Chip information website Yite Chuangxin
[UVM foundation] what is transaction
2022焊工(初级)判断题及在线模拟考试
The principle and implementation of buffer playback of large video files
[quick start of Digital IC Verification] 15. Basic syntax of SystemVerilog learning 2 (operators, type conversion, loops, task/function... Including practical exercises)
Content of string
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
快解析内网穿透为文档加密行业保驾护航
uniapp 移动端强制更新功能
JS quick start (I)
探索干货篇!Apifox 建设思路
Open source ecosystem | create a vibrant open source community and jointly build a new open source ecosystem!