我有一些代码在vue.js中发送https请求,并且在vuex中使用动作方法发送https请求时,在控制台“ GEThttps://localhost/api/getpeoplenet :: ERR_SSL_SERVER_CERT_BAD_FORMAT”中收到此错误
我的代码是:
import Axios from "axios";
let state = {
people: []
};
let getters = {
getPeople(state) {
return state.people;
}
}
let mutations = {
setPeople(state, people) {
state.people = people
}
}
let actions = {
sendHttpReq({ commit }) {
Axios.get('https://localhost:443/api/getpeople',{ withCredentials:
true}).then(response=>response.data).then(result=>{
commit('setPeople',result);
}).catch(error=>{
console.log(error.response)
})
}
}
export default {
state,
getters,
mutations,
actions
}
let express=require('express');
let cors=require('cors');
let https=require('https');
let pem=require('pem');
let mydb=require('./mydb')
pem.createCertificate({days:1,selfSigned: true},(err,keys)=> {
if (err)
return err;
let app = express();
app.use(express.json());
app.use(cors());
app.post('/api/setPeople', (req, res) => {
let body = req.body;
mydb.insert(body.firstName, body.lastName, body.phone, (result) => {
res.status(200).send(result)
});
});
app.get('/api/getpeople', async (req, res) => {
mydb.getPoeple((result) => {
console.log(result);
res.status(200).send(result)
});
});
https.createServer({key: keys.serviceKey, cert: keys.certificate}, app).listen(443, () => {
console.log('server is run ' + 443);
});
})
这是发送https请求并获取响应并设置为人员的代码,其他代码将人员显示在表中。其他代码正确,但是此代码有问题
[axios
执行GET
请求,您应该在url中发送数据