如何在 IE11 上使用 Bitly V4 URL Shorten API

How to use Bitly V4 URL Shorten API on IE11

我正在尝试通过 ajax POST 在 IE11 上使用 Bitly V4 URL Shorten API,但在预检 (OPTIONS) 调用后出现安全错误。我的实现和遇到的错误如下:

我的代码:

$.ajax({
    type: 'POST',
    url: 'https://api-ssl.bitly.com/v4/shorten',
    data: JSON.stringify({group_guid: '<Bitly_group_guid>', long_url: 'https://www.google.com'}),
    dataType: 'json',
    contentType: 'application/json',
    headers: {
        'Authorization': 'Bearer <Bitly_generic_access_token>',
    },
}).done(function (resp) {
    console.log('OK');
}).fail(function (jqXHR, textStatus, errorThrown) {
    console.log('NOT OK');
});

IE11 控制台错误(预检后抛出):

SEC7123: Request header content-type was not present in the Access-Control-Allow-Headers list.

SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.

预检(选项)响应 Header - 响应代码 200:

access-control-allow-headers: *

access-control-allow-methods: HEAD, GET, POST, PUT, PATCH, DELETE

access-control-allow-origin: *

allow: POST, OPTIONS

alt-svc: clear

content-length: 0

content-security-policy: default-src 'none

date: Thu, 28 Nov 2019 03:13:04 GMT

server: nginx

strict-transport-security: max-age=31536000; includeSubDomains

via: 1.1 google

x-content-type-options: nosniff

x-frame-options: DENY

x-xss-protection: 1; mode=blockFilter

最后 POST 方法根本不执行,相同的代码但是在 Chrome 和 Mozilla 上运行,POST 方法得到执行并设法缩短 URL.

如果有人可以分享解决此问题的见解,我们将不胜感激。

查看文档后,我找到了有关浏览器对 Bitly 支持的信息 api。

The Bitly web app supports the latest versions of Chrome, Firefox, Edge, and Safari. We recommend using one of these browsers for full functionality of the web app.

Other browsers are not tested and may not function properly with the Bitly web app.

参考:

Which browsers does the Bitly web app support?