码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-10-17 13:43:45      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

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. }







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

标签:

原文地址:http://www.cnblogs.com/tangruixin/p/5969305.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!