0

我正在使用Outlook API 的这一部分。它说您应该能够进行发布请求,但是当我尝试时出现以下错误:

Failed to load https://login.microsoftonline.com/common/oauth2/v2.0/token: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3003' is therefore not allowed access. The response had HTTP status code 400.

我该如何解决这个问题?我显然无权访问 Outlook 的服务器,但考虑到文档中所说的内容,他们肯定会让我发帖请求!.

顺便说一下,如果有帮助,这是我的代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
  let url = new URL(window.location);
  let code = url.searchParams.get('code');
  let redirect = 'http%3A%2F%2Flocalhost%3A3003%2Fauth-process-token.html';
  let clientId = '<MY ID>';
  let clientSecret = '<MY KEY>';

  var req_string = 'grant_type=authorization_code&code=' + code + '&redirect_uri=' + redirect + '&client_id=' + clientId + '&client_secret=' + clientSecret;

  $.ajax({
    type: 'POST',
    url: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
    crossDomain: true,
    data: req_string,
    dataType: 'application/x-www-form-urlencoded',
    success: function (responseData, textStatus, jqXHR) {
      var value = responseData.someKey;
    },
    error: function (responseData, textStatus, errorThrown) {
      console.log('POST failed.', errorThrown);
    }
  });
</script>

编辑:我修复了“错误请求”错误,但它仍然给了我另一个错误。

4

1 回答 1

0

一种解决方法是使用 cors.io

http://cors.io/?http://your_link

所以它会是

http://cors.io/?https://login.microsoftonline.com/common/oauth2/v2.0/token
于 2017-12-18T03:58:57.243 回答