Home >Web Front-end >uni-app >The uniapp package request cannot be accessed
In recent years, with the popularization of mobile Internet and the continuous advancement of development technology, APP has become more and more popular among people. Among them, uniapp is a cross-platform development framework that can develop APPs for multiple operating systems at the same time and can be directly packaged and deployed. However, when many developers use uniapp for packaging, they will encounter the problem that some requests cannot be accessed. This article will introduce the reasons and solutions for why uniapp packaging requests cannot be accessed from three aspects.
1. CORS Issues
CORS (Cross-Domain Resource Sharing) is a network standard for cross-domain access. Although CORS allows network communication between servers from different origins, it can also cause some security issues. Therefore, browsers generally restrict certain HTTP requests from different origins. This is an important reason why the uniapp package request cannot be accessed.
Solution:
devServer: { proxy: { '/api': { target: 'http://localhost:8080',//这里改成你自己的服务器地址 changeOrigin: true, pathRewrite: { '^/api': '/', }, }, }, },
2. HTTPS issues
When a request is initiated in the APP, if the request address is the http protocol, it will be considered unsafe, and the browser will automatically forward the http request. However, after uniapp is packaged, if you do not change all request addresses to https protocol, then the request may not be accessible.
Solution:
Change all request addresses to https protocol.
3. Network issues
When we use uniapp to package, if the network environment is not good or there is a network failure, the request will not be accessible.
Solution:
Summary:
As a cross-platform development framework, uniapp facilitates developers to develop APPs for multiple operating systems at the same time, and can be directly packaged and deployed. When using uniapp for packaging, you encounter the problem that the request cannot be accessed. This article proposes several possible reasons and solutions. In actual development, adjustments need to be made according to specific circumstances to ensure the normal operation of the APP.
The above is the detailed content of The uniapp package request cannot be accessed. For more information, please follow other related articles on the PHP Chinese website!