Microsoft Academic Search API 停止工作

Microsoft Academic Search API stopped working

我成功地使用了 Microsoft Academic Search API 但由于某种原因,我未更改的代码在大约 2 周前停止工作,不知道为什么。我把它归结为一些 CORS 问题:预检 OPTIONS 请求导致 404 并使用 mode: 'no-cors' 直接 POST 阻止自定义 API-key header (Ocp-Apim-Subscription-Key) 被发送,导致 401。当一切仍在工作时,我从未查看过网络 dev-tab,也许 OPTIONS 请求在两周前仍然有效?或者它可能是我这边的 Firefox 更新?

我试过 GET 和 POST 请求,我试过 axios 和 fetch API,我试过 no-cors 和 cors 请求。除了手动将 API-key 添加到 header.

外,什么都不起作用
// simple no-cors request
fetch(
    'https://api.labs.cognitive.microsoft.com/academic/v1.0/evaluate',
    {
        method: 'POST',
        mode: 'no-cors', // I've tried removing this line for CORS request
        headers: new Headers(
           { "Content-Type": "application/x-www-form-urlencoded", "Ocp-Apim-Subscription-Key":"[actual key not needed for replication]" }
        ),
        body: "expr=Id%3D2101196984&attributes=Id"
    }
).then( response => { console.log(response);} )
.catch(err => console.log(err))

看看 Ocp-Apim-Subscription-Key header 怎么不见了。经过一些研究,我意识到这是由于 no-cors 模式 (see here)。简单 POST header:

Host: api.labs.cognitive.microsoft.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded
Origin: null
Content-Length: 34
DNT: 1
Connection: keep-alive

此请求导致 401,权限被拒绝。请注意,我在示例中使用了虚拟密钥,但我的真实密钥也遇到了同样的问题,这一定是由于 Ocp-Apim-Subscription-Key 的遗漏,因为 当我重新发送请求时手动添加 key-header 后,响应正常 (在开发人员工具栏网络中使用 Firefox 的 "Edit and Resend" 功能=>Headers 选项卡并手动添加一行 Ocp-Apim-Subscription-Key: [actual key]).

但是,当我使用CORS请求时,服务器无法真正处理以下OPTIONS预检请求,返回404。

Request OPTIONS header 在发送与上面相同的 fetch-request 时发生,只是没有 mode: 'no-cors'

Host: api.labs.cognitive.microsoft.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Access-Control-Request-Method: POST
Access-Control-Request-Headers: ocp-apim-subscription-key
Origin: null
DNT: 1
Connection: keep-alive

响应header:

HTTP/1.1 404 Resource Not Found
Content-Length: 89
Content-Type: application/json
Date: Mon, 28 Oct 2019 10:59:03 GMT

还有其他人遇到这个问题吗?我能做些什么吗?这似乎是 Microsoft 方面的服务器问题?

我很高兴地说,CORS 问题应该最终得到解决。问题本身是内部迁移期间配置错误的结果。

抱歉延迟解决!