【发布时间】:2020-06-10 10:01:55
【问题描述】:
我正在尝试使用 Express 和 got 通过我的服务器代理 GitHub 用户头像。
没有rejectUnauthorized: false,以下代码块返回错误:
GotError:主机名/IP 与证书的替代名称不匹配:主机: 本地主机。不在证书的替代名称中:DNS:www.github.com, DNS:.github.com, DNS:github.com, DNS:.github.io, DNS:github.io, DNS:*.githubusercontent.com, DNS:githubusercontent.com
使用rejectUnauthorized: false,返回错误:
HTTPError:响应代码 404(未找到)
我做错了什么?
const server = express()
server.get("/api/github/:username", async (req, res) => {
if (!req.params.username) {
res.sendStatus(400)
} else {
try {
const stream = got.stream(
`https://avatars.githubusercontent.com/${req.params.username}?size=64`,
{
rejectUnauthorized: false,
}
)
stream.on("error", error => {
res.sendStatus(500)
})
req.pipe(stream).pipe(res)
} catch (error) {
res.sendStatus(400)
}
}
})
【问题讨论】:
-
一旦我遇到与 axios 相同的问题,解决方案是在配置对象中指定主机,在您的情况下将是 'avatars.githubusercontent.com'
-
感谢您的反馈。刚刚尝试添加
host或hostname并出现同样的错误。