使用不支持的媒体类型更新邮箱设置失败(415)

时间:2018-02-11 22:25:29

标签: c# webclient outlook-restapi

通过协商Oauth2标记之类的迷宫,我可以使用以下方式从Outlook REST API获取MailboxSettings

https://outlook.office.com/api/v2.0/me/mailboxsettings 

我现在正尝试使用Outlook Mail REST API参考示例更新mailboxsettings(自动回复设置)。

我正在使用c#webclient:

URI = "https://outlook.office.com/api/v2.0/me/mailboxsettings";
data = "{\"@odata.context\":
\"https://outlook.office.com/api/v2.0/$metadata#Me/MailboxSettings\",
\"AutomaticRepliesSetting\": {\"Status\": \"Scheduled\",
\"ExternalAudience\": \"None\", \"ScheduledStartDateTime\":
{\"DateTime\": \"2018-02-20T02:00:00.0000000\", \"TimeZone\":
\"UTC\"}, \"ScheduledEndDateTime\": { \"DateTime\":
\"2018-02-28T02:00:00.0000000\", \"TimeZone\": \"UTC\" },
\"InternalReplyMessage\": \"<html>\n<body>\n<p>I'm at our company's
worldwide reunion and will respond to your message as soon as I
return.<br>\n</p></body>\n</html>\n\", \"ExternalReplyMessage\":
\"<html>\n<body>\n<p>I'm at the Contoso worldwide reunion and will
respond to your message as soon as I
return.<br>\n</p></body>\n</html>\n\" }, \"TimeZone\": \"Pacific
Standard Time\", \"Language\":{ \"Locale\":\"en-US\",
\"DisplayName\":\"English (United States)\" } } ";

wc.UploadString(URI, "PATCH", data);

最后一行给了我一个例外:

  

远程服务器返回错误:(415)不支持的媒体类型。

我不知道这意味着什么。感激地收到任何建议

1 个答案:

答案 0 :(得分:1)

您需要将Content-Type标头设置为application/json