最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

使用基本身份验证重定向到另一个网站(在节点中)

运维笔记admin12浏览0评论

使用基本身份验证重定向到另一个网站(在节点中)

使用基本身份验证重定向到另一个网站(在节点中)

如何使用基本身份验证重定向到另一个网站(在节点中)

这是我的代码

const headers = {
  Authorization: "Basic " + 
  new Buffer(USER + ":" + PASS).toString("base64")
};

ctx.response.set(headers);
ctx.response.redirect(URL)

第一个响应返回基本身份验证

Authorization →Basic QWRxXxXxYWRtaW4=
Connection →keep-alive
Content-Length →111
Content-Type →text/html; charset=utf-8
Date →Fri, 15 Dec 2017 21:49:57 GMT
Location →http://localhost:8080/edit/data/P0000013

以下重定向的GET请求不包含基本身份验证并再次重定向到登录页面。

# General
Request URL:http://localhost:8080/edit/data/P0000013
Request Method:GET
Status Code:302 Found
Remote Address:[::1]:8080
Referrer Policy:no-referrer-when-downgrade

# Request Header
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.9
Connection:keep-alive
Cookie:....
Host:localhost:8080
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
回答如下:

您可以指定用户名和密码作为URL的一部分:

ctx.redirect('http://username:[email protected]');
发布评论

评论列表(0)

  1. 暂无评论