获取 Outlook ics url 时出现“错误请求 400”响应

jim*_*bus 5 javascript outlook request node.js office365

我在获取 ical feed 的遗留项目中遇到了问题。

尝试通过任何 Outlook.office365 网址获取日历时,我收到“错误请求 400”的响应。

我已经使用 PostMan 和在线 ics 验证器测试了所有网址,因此我知道这与日历本身不可用无关。

我正在使用 npm 包“请求”来获取日历,它可以处理任何不是来自 Outlook.office365.com 主机的 URL。

出于隐私原因,我无法分享任何使用的网址。

这是发送请求的地方。

async.waterfall([
        cb => {
          request.get(url, {}, function (err, r, data) {
            console.log('response', r.statusCode); // this will be 400 for any outlook.office365 ics url but not for others.
            if (err) return cb(err, null);
            try {
              ...
            } catch (err) {
              ...
            }
Run Code Online (Sandbox Code Playgroud)

是否需要附加任何标题才能接收 Outlook.office365 日历?我在网上找不到任何有关所需内容的信息

小智 0

我遇到过同样的问题。我比较了 Postman 中的请求标头,并尝试在我的应用程序中模仿这些标头。添加邮递员用户代理字符串使其对我有用:

        HttpClient myHttpClient = new HttpClient();

        myHttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
        myHttpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("PostmanRuntime","7.30.1"));

        var response = myHttpClient.GetAsync(calendarUrl).Result;
Run Code Online (Sandbox Code Playgroud)