XmlHttpRequest发送错误的JSESSIONID

时间:2017-06-25 20:45:29

标签: angular rest spring-security xmlhttprequest

我正在尝试使用XMLHttpRequest将文件发送到我的后端。在后端我使用弹簧安全。前端使用Angular 2.问题是XMLHttpRequest发送一个完全不同的JSESSIONID Cookie(总是相同的)并被拒绝访问。我使用Angular' http.post的其他请求发送了正确的JSESSIONID。错误的JSESSIONID似乎无处不在,我无法确定原因。

这是我的XMLHttpRequest:

  postFormData() {
      return fromPromise(new Promise((resolve, reject) => {
      let formData: any = new FormData()
      let xhr = new XMLHttpRequest()

      formData.append("file", this.file, this.file.name);

      xhr.onreadystatechange = function() {
          if (xhr.readyState === 4) {
              if (xhr.status === 200) {
              resolve(xhr.response)
          } else {
              reject(xhr.response)
      }
  }};


  console.log("sending stuff")
  //xhr.setRequestHeader();
  xhr.open("POST", 'http://localhost:8080/import/loadsheets', true);
  //xhr.setRequestHeader("withCredentials","true");
  xhr.withCredentials = true;
  //xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
  xhr.setRequestHeader("Access-Control-Allow-Credentials", "true");
  //let sess = this.cookieService.get("cookie");
  //console.log('Cookie: ', sess);
  //xhr.setRequestHeader('Cookie', sess);
  xhr.send(formData)
}));
}

这是预检: enter image description here

这是实际请求(使用错误的JSESSIONID): enter image description here

问题是什么?提前谢谢!

0 个答案:

没有答案
相关问题