简体   繁体   中英

“SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.” in IE11 with fetch API

I'm calling an external POST request from localhost with JavaScript's fetch function.

Everything is working fine with all the browsers except for IE11, which is returning this error on the request:

“SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.” in IE

This is the code:

export const signIn = (email, password) => {
  const base64 = btoa(`${email}:${password}`);
  const headers = new Headers({
    Authorization: `Basic ${base64}`
  });
  return new Promise((resolve, reject) => {
    fetch(`${__API__}/spa/token`, {
      method: "POST",
      headers,
      credentials: "include"
    })
      .then(resp => {
        if (resp.status >= 400) {
          reject(resp);
        }
        resolve(resp);
      })
      .catch(reject);
  });
};

One of the "solutions" that I've read it this other thread ( How to solve the error "SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied." in IE ) was to change IE's configuration here:

Internet Options> Security > ENABLE The Following setting: Miscellaneous > Access data sources across domains.

For me, that's not a solution because I'll won't request the final user to change his/her configuration.

Also, when I'm inspecting the request in IE, I can see that the POST is actually being called as a GET.

UPDATE : If I remove the headers option it works, but I need the headers.

Ok, so this was the solution for me:

I discovered that the issue was to send the fetch with headers. If first I send it without the headers (like a preflight request) and then send it normally it just works.

Of course, this is just for IE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM