当前位置:网站首页>[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)
边栏推荐
- Shell 脚本的替换功能实现
- 【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
- Recursive method to construct binary tree from preorder and inorder traversal sequence
- Ansible
- JS cross browser parsing XML application
- mysql多列索引(组合索引)特点和使用场景
- These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
- Roulette chart 2 - writing of roulette chart code
- Real time monitoring of dog walking and rope pulling AI recognition helps smart city
- Summary of redis functions
猜你喜欢
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
Linux server development, redis protocol and asynchronous mode
Content of string
Li Kou interview question 04.01 Path between nodes
Avatary的LiveDriver试用体验
Yugu p1020 missile interception (binary search)
2022焊工(初级)判断题及在线模拟考试
Ansible
Force buckle 145 Binary Tree Postorder Traversal
让Livelink初始Pose与动捕演员一致
随机推荐
Cnopendata geographical distribution data of religious places in China
offer收割机:两个长字符串数字相加求和(经典面试算法题)
2022焊工(初级)判断题及在线模拟考试
力扣(LeetCode)187. 重复的DNA序列(2022.07.06)
Introduction à l'objet blob
Binary tree and heap building in C language
太真实了,原来自己一直没有富裕起来是有原因的
Bugku CTF daily one question chessboard with only black chess
buureservewp(2)
Network learning (III) -- highly concurrent socket programming (epoll)
game攻防世界逆向
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
[UVM foundation] what is transaction
UnityHub破解&Unity破解
复杂网络建模(三)
【数字IC验证快速入门】10、Verilog RTL设计必会的FIFO
Relevant data of current limiting
海信电视开启开发者模式
青龙面板-今日头条
Linux server development, SQL statements, indexes, views, stored procedures, triggers