如何更新邮件类别.正在获得“空有效负载.调用Microsoft Graph时出现“预期的JSON内容"错误 [英] How to update a Mail Message Category. Was getting “Empty Payload. JSON content expected” error calling Microsoft Graph

查看:87
本文介绍了如何更新邮件类别.正在获得“空有效负载.调用Microsoft Graph时出现“预期的JSON内容"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了一些与此问题相同的问题.我想我已经准备就绪,但是仍然收到"Empty Payload"错误.有人看到遗失的东西了吗?

I have seen a few questions posted with this same problem. I think I have all the pieces, but I am still getting the "Empty Payload" error. Does anyone see what is missing?

我想更新某些邮件的类别.我正在使用Beta端点,是因为该帖子: Microsoft Graph Client SDK与请求JSON

I want to update the category of some mail messages. I am using the beta endpoint because of this post: Microsoft Graph Client SDK vs. Requesting JSONs

这是我的代码:

public async void UpdateMailCategory(GraphServiceClient graphClient, string messageId, string inbox)
{

    string newCategory = @"{'categories': ['Processed']}";

    try
    {
        // Get the request URL for adding a page. 
        string requestUrl = graphClient
            .Users[inbox]
            .Messages[messageId]
            .Request()
            .RequestUrl;

        HttpRequestMessage hrm =
            new HttpRequestMessage(new HttpMethod("PATCH"), requestUrl);
        hrm.Content =
            new StringContent(newCategory, Encoding.UTF8, "application/json");

        // Authenticate (add access token) our HttpRequestMessage
        await graphClient.AuthenticationProvider
            .AuthenticateRequestAsync(hrm);

        // Send the request and get the response.
        HttpResponseMessage response =
            await graphClient.HttpProvider.SendAsync(hrm);
    }
    catch (ServiceException Servex)
    {
        throw Servex;
    }
}

当我看着hrm.content时,它显示了这一点:

When I look at the hrm.content, it shows this:

{ System.Net.Http.StringContent }
Headers:
{
    Content - Type : application / json;charset = utf - 8
    Content - Length : 35
}

推荐答案

您正在使用Graph Client SDK是一种绕行的方式,比其他任何方式都更可能使您头疼.还会导致不必要的复杂代码.

You're using the Graph Client SDK is a rather roundabout way which is more likely going to cause you headaches than anything else. It also leads to more complicated code than necessary.

SDK包含了整个请求所需的一切.除了边缘情况外,您永远不需要处理HttpProvider实例或管理HttpRequestMessageHttpResponseMessage实例.

The SDK includes everything you need for the entire request. With the exception of an edge case, you should never need to deal with the HttpProvider or manage HttpRequestMessage and HttpResponseMessage instances.

以下将完成相同的事情(设置消息的Categories属性),而复杂度要低得多:

The following will accomplish the same thing (setting the Categories property of a message) with a lot less complexity:

public async void UpdateMailCategory(GraphServiceClient graphClient, string messageId, string inbox)
{
    try
    {
        await graphClient
            .Users[inbox]
            .Messages[messageId]
            .Request()
            .UpdateAsync(new Message()
            {
                Categories = new List<string>() { "Processed" }
            });
    }
    catch (ServiceException Servex)
    {
        throw Servex;
    }
}

此操作也不应使用/beta版本,因为版本支持 .您只需要利用/beta版本来管理用户的类别,因为该尚不可用.

You also shouldn't use the /beta version for this operation as it is supported by the /v1.0 version. You should only need to leverage the /beta version to manage the user's Categories since this isn't generally available yet.

这篇关于如何更新邮件类别.正在获得“空有效负载.调用Microsoft Graph时出现“预期的JSON内容"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆