Polymer.js基本授权不起作用

Polymer.js基本授权不起作用,polymer,polymer-1.0,Polymer,Polymer 1.0,我正在执行一个跨源请求,以从具有基本身份验证的url获取json响应。因此,点击按钮,我将设置基本身份验证的标题。当我在发送请求之前打印出这些值时,我会看到它们。但是当我检查chrome开发工具的请求时,我没有看到设置了头。此外,该请求变成来自“GET”请求的“Options”请求,响应为401 unauthorized。我丢了什么东西吗 <paper-input type="search" value="{{imageUrl}}" placeholder="Enter Image UR

我正在执行一个跨源请求,以从具有基本身份验证的url获取json响应。因此,点击按钮,我将设置基本身份验证的标题。当我在发送请求之前打印出这些值时,我会看到它们。但是当我检查chrome开发工具的请求时,我没有看到设置了头。此外,该请求变成来自“GET”请求的“Options”请求,响应为401 unauthorized。我丢了什么东西吗

 <paper-input type="search" value="{{imageUrl}}" placeholder="Enter Image URL"></paper-input> 
  <div class="buttons">
    <paper-button on-tap="getData" autofocus>Search</paper-button>
  </div>
  <iron-ajax
  id="xhr"
  url="https://api.com/v1"
  params='{"url":"some query value"}'
  handle-as="json"
  method="GET"
  last-response="{{ajaxResponse}}"></iron-ajax>

  getData: function(){
    this.$.xhr.headers['X-Requested-With'] = "XMLHttpRequest";
    this.$.xhr.headers['Authorization'] = this.makeHeaders(this.user, this.password);
    this.$.xhr.generateRequest();
  }

搜寻
getData:function(){
此.xhr.headers['X-request-With']=“XMLHttpRequest”;
this.$.xhr.headers['Authorization']=this.makeHeaders(this.user,this.password);
这是$.xhr.generateRequest();
}

默认情况下,
iron ajax
默认情况下不发送跨站点请求的

您可以通过在
iron ajax
上设置
withCredentials
属性来更改此设置:

<iron-ajax
  id="xhr"
  url="https://api.com/v1"
  params='{"url":"some query value"}'
  handle-as="json"
  with-credentials="true"
  method="GET"
  last-response="{{ajaxResponse}}"></iron-ajax>

这使我相信浏览器正在使用options方法向“”发送飞行前请求您需要通过发送回http状态200来处理该选项方法,然后您的调用应该得到正常处理。请检查以下URL:@getBucks它实际上是我正在使用的第三方api服务,当我从postman处执行该服务时,它会正常工作。我还尝试了safari和firefox,但都显示了相同的失败消息。不确定我做错了什么你能展示一下“this.makeHeaders()”代码的功能吗?makeHeaders:function(user,password){return“Basic”+btoa(user+”:“+password);},
this.$.xhr.withCredentials = true;