0
Follow
0
View

How to change vue to https request

easonlele 注册会员
2023-02-28 00:45

Server domain name Apply for SSL/TLS certificate, the front-end change the requested URL from http// to https// start

donglei55 注册会员
2023-02-28 00:45

Hope to help you, wish you a happy life!

tianxiawub 注册会员
2023-02-28 00:45

This answer references ChatGPT
To change the HTTP request from Vue2 to HTTPS, you need to do the following:

  1. Install SSL certificates on the server to support the HTTPS protocol.
  2. Configure HTTPS requests in Vue2, which can be done using libraries such as axios or fetch.
  3. Configure the URL of the HTTPS request in Vue2 and use HTTPS.
  4. Configure the request header of the HTTPS request in Vue2 to support HTTPS.
  5. Configure the response header of the HTTPS request in Vue2 to support HTTPS.

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请求已经访问成功。

dqj0618 注册会员
2023-02-28 00:45
I don't know if your problem has been solved yet, if not:
  • has found a very good blog for you to see if it helps.

If you've solved this problem, I'd really like you to share your solution and blog about it, Put related links in the comments section to help more people ^-^
chenyb0513 注册会员
2023-02-28 00:45

My back end is ABP. Do I need to change this back end?

eastnet1 注册会员
2023-02-28 00:45

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'
})

ya313584699 注册会员
2023-02-28 00:45

First, your server should support https. If it does, change http to https in the request address.

dd330825197610124545 注册会员
2023-02-28 00:45

backend nginx with a proxy is OK

dengh_dhsea 注册会员
2023-02-28 00:45

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

wuyi3320 注册会员
2023-02-28 00:45

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.

  1. You need a domain name
  2. You need to apply for an ssl certificate for this domain name, either using Aliyun for free, or Tencent Cloud for free, or let's encrypt
  3. you need a server on the interface you provide such as nginx Configuring an ssl Certificate

About the Author

Question Info

Publish Time
2023-02-28 00:45
Update Time
2023-02-28 00:45