我正在尝试使用 vue-axios 通过 https 进行发布请求。但是,由于我使用的是我创建的自签名证书,因此出现以下错误:
net::ERR_CERT_AUTHORITY_INVALID
经过搜索,我发现大多数人通过执行以下操作来解决此问题
const instance = axios.create({
httpsAgent: new https.Agent({
rejectUnauthorized: false
})
});
instance.get('https://something.com/foo');
// At request level
const agent = new https.Agent({
rejectUnauthorized: false
});
axios.get('https://something.com/foo', { httpsAgent: agent });
Run Code Online (Sandbox Code Playgroud)
我尝试了这两种选择,但都没有成功。我为 https.Agent 使用了 npm https 模块。
有谁知道如何解决这个问题?还是我应该从 axios 更改为其他模块?
编辑:
我目前正在运行的代码段出现错误:
const axiosInstance = axios.create({
baseURL: 'https://localhost:5000',
httpsAgent: new https.Agent({
rejectUnauthorized: false
}),
});
axiosInstance.post('/user', LoginRequest,
{ headers: { 'Content-Type': 'application/json' } })
.then(response => this.assignLogin(response.data));
Run Code Online (Sandbox Code Playgroud)
尝试更改为名为needle 的模块并使用https,但出现相同的错误:
针:
const headers = { 'Content-Type': …Run Code Online (Sandbox Code Playgroud)