我正在尝试使用 Azure 函数通过其 ID 转发 Outlook 电子邮件。
var url = "https://graph.microsoft.com/v1.0/users('<blah>')/messages/" + ID + "/forward";
var content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
var response = await client.PostAsJsonAsync(url, content);
log.Info(response.Content.ReadAsStringAsync().Result);
我得到的结果是 The value of the parameter 'ToRecipients' is empty. Specify 'ToRecipients' either in the message object or in the action.
我传入的数据变量是 {"message":{"ToRecipients":[{"emailAddress":{"address":"<blah>"}}]}}
.
我做错了什么?如何成功发布数据 JSON 对象?我觉得我已经尝试了网上能找到的所有示例,但没有任何运气。
仅供引用, token 已附加到 header ,我只是没有显示该部分。
最佳答案
您似乎对要发送的数据进行了双重序列化。
首先当您手动序列化时
...JsonConvert.SerializeObject(data)...
第二个是当您调用PostAsJsonAsync
client.PostAsJsonAsync(url, content);
它会在发布之前将提供的对象序列化为 JSON。
如果调用PostAsJsonAsync
,则无需手动创建内容
//...
var url = "https://graph.microsoft.com/v1.0/users('<blah>')/messages/" + ID + "/forward";
var response = await client.PostAsJsonAsync(url, data);
var result = await response.Content.ReadAsStringAsync();
log.Info(result);
//...
关于c# - 将 JSON 数据发布到 Microsoft Graph API Azure Function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53587456/