首页 > 代码库 > https和http 调用过程中请求头 referrer 获取不到的问题

https和http 调用过程中请求头 referrer 获取不到的问题

HTTP协议规定:
  1. Clients SHOULD NOT include a Referer header field in a (non-secure) HTTP request if the referring page was transferred with a secure protocol.

解决办法:
1、表单添加一个字段referrer,如果头部没有Referer,则获取表单的这个字段,
     添加js:
  1. <input id="referrer" type="hidden" name="referrer" />
  2. <script type="text/javascript">
  3. document.getElementById("referrer").value = window.location.href
  4. </script>

2、后台:
  1. string urlReferrer = "";
  2. if (Request.UrlReferrer == null)
  3. {
  4. urlReferrer = Request["referrer"];
  5. }
  6. else
  7. {
  8. urlReferrer = Request.UrlReferrer.AbsoluteUri;
  9. }





来自为知笔记(Wiz)


https和http 调用过程中请求头 referrer 获取不到的问题