【问题标题】:How to Address "Refused to Set Unsafe Header: Connection"?如何解决“拒绝设置不安全的标头:连接”?
【发布时间】:2011-11-03 17:48:36
【问题描述】:

我正在使用 Prototype 结合 CodeIgniter 来提交 AJAX 请求。我的浏览器是 Chrome。我在控制台中收到一条错误消息,显示为“拒绝设置不安全的标头:连接”。这是 Ajax 请求行:

new Ajax.Request('/vbs/index.php/signup/get_ratecenters',{method:'POST', evalScripts:true})

我尝试将类型设置为同步,但收到了同样的错误。

有人可以帮忙吗?提前致谢。

【问题讨论】:

    标签: php javascript ajax codeigniter prototypejs


    【解决方案1】:

    prototype.js (1.7.0.0) 中只有一个代码片段尝试设置 Connection: close 标头

    if (this.method == 'post') {
      headers['Content-type'] = this.options.contentType +
        (this.options.encoding ? '; charset=' + this.options.encoding : '');
    
      /* Force "Connection: close" for older Mozilla browsers to work
       * around a bug where XMLHttpRequest sends an incorrect
       * Content-length header. See Mozilla Bugzilla #246651.
       */
      if (this.transport.overrideMimeType &&
          (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
            headers['Connection'] = 'close';
    }
    

    如果您使用的是prototype.js 的本地副本,您可以将代码片段更改为

    if (this.method == 'post') {
      headers['Content-type'] = this.options.contentType +
        (this.options.encoding ? '; charset=' + this.options.encoding : '');
    
      /* Force "Connection: close" for older Mozilla browsers to work
       * around a bug where XMLHttpRequest sends an incorrect
       * Content-length header. See Mozilla Bugzilla #246651.
       */
      if (this.transport.overrideMimeType &&
          (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
      {
            alert("Yes, this is it.");
                if ( navigator.userAgent.match(/Gecko\/(\d{4})/) ) {
                    alert("navigator");
                }
            headers['Connection'] = 'close';
      }
    }
    

    看看是不是真的原因。

    【讨论】:

      【解决方案2】:

      如果您直接在浏览器中加载/vbs/index.php/signup/get_ratecenters 会发生什么?

      read somewhere online 说“拒绝设置不安全的标头:连接”是一个警告,无法设置 HTTP 的“连接”标头,但并不意味着该请求不会被处理,因此可能会发生其他事情在这里?

      检查 /vbs/index.php/signup/get_ratecenters 并确保它返回有效的 JavaScript 代码。在 Chrome 控制台中执行该代码并确保它没有错误...这里可能是另一个错误。

      【讨论】:

      • 乔希,你有任何关于如何面对这个问题的更新吗,我的第一个带有“Connection”和“Keep-Alive”标头的请求在处理时会出现你提到的警告--->“拒绝设置不安全的标头“连接”。”我随后的请求失败。能否请您对此有所了解...谢谢
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-16
      • 2011-11-04
      • 1970-01-01
      • 2016-01-13
      • 2014-07-07
      • 1970-01-01
      相关资源
      最近更新 更多