Server domain name Apply for SSL/TLS certificate, the front-end change the requested URL from http// to https// start
Background description: I am currently using vue2, the request to the server is http format, leader requires to use https instead.
I initiated the request in axios mode on vue2.
I looked for some information on the Internet, but I still don't have a clue.
Question: Please help to advise, is there a good solution, in addition to the server to make any corresponding changes? Thanks!
0 Answer
Server domain name Apply for SSL/TLS certificate, the front-end change the requested URL from http// to https// start
This answer references ChatGPT
To change the HTTP request from Vue2 to HTTPS, you need to do the following:
Method 2
要使用https的话,首先你的服务端需要配置SSL证书,然后使用Vue2的框架请求服务端接口的时候,要将你的请求改为https的格式,具体步骤如下:
1. 在vue项目的入口文件main.js中,全局配置axios为https协议
import axios from 'axios';
// 配置axios为https
axios.defaults.baseURL = 'https://www.xxx.com';
2. 在组件中引用axios发送请求
// 商品列表
getGoodsList() {
axios.get('/goods/list')
.then((response) => {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
3. 确认调试接口是否成功
在浏览器地址栏输入https://www.xxx.com/goods/list 查看调试结果,如果成功即可表示您的https请求已经访问成功。
Please use this
You can use Vue's axios module to change Vue's HTTP requests to HTTPS requests. First, you need to install the axios module in the Vue project, then introduce the axios module in the main.js file and change Vue's HTTP request to an HTTPS request, as follows:
import axios from 'axios'
Vue.prototype.$http = axios.create({
baseURL: 'https://example.com'
})
First, your server should support https. If it does, change http to https in the request address.
The front end only needs to change the protocol of the request link to https. Whether the project supports https is mainly the configuration of the server, and the https certificate is added to the server nginx. As a front-end you just change the link protocol
If you are only responsible for the front end, then your work is basically zero, change the requested url from
"http://xxx" 变更为 "https://xxxx"
If you're also responsible for the back end, it's a lot more work.
这家伙很懒,什么都没留下...