如何处理“拒绝设置不安全标头:连接”


How to Address "Refused to Set Unsafe Header: Connection"?

我使用Prototype结合CodeIgniter来提交AJAX请求。我的浏览器是Chrome。我在控制台收到一个错误,上面写着"拒绝设置不安全的头:连接"。下面是Ajax请求行:

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

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

有人能帮忙吗?

在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';
  }
}

,看看这是不是真正的原因。

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

我在网上某处读到"拒绝设置不安全的头:连接"是一个警告,HTTP"连接"头不能设置,但并不意味着请求不会被处理,所以有可能这里发生了别的事情?

检查/vbs/index.php/signup/get_ratecenters并确保它返回有效的JavaScript代码。执行该代码在Chrome控制台,并确保它是错误的自由…这里可能有不同的错误