获取 Outlook ICS URL 时出现"错误请求 400"响应



我在一个获取ical提要的遗留项目中遇到了问题。

我得到的答复是";错误的请求400〃;当试图通过任何outlook.office365 url获取日历时。

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

我正在使用npm包"request"来获取日历,它可以处理任何不是来自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) {
...
}

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

我遇到了同样的问题。我比较了Postman中的请求标头,并尝试在我的应用程序中模仿这些标头。添加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;

看起来服务器希望存在一些用户代理HTTP标头。

像这样的请求已经对我有效了。

request(
{ url : url,
headers: {
'User-Agent': 'request'
}
}
...

最新更新