简体   繁体   English

如何在 c# Microsoft graph api 请求中获得响应 header

[英]How to get response header in c# Microsoft graph api request

I am trying to do File Copy operation in c# .net core using Microsoft graph API.我正在尝试使用 Microsoft graph API 在 c# .net 内核中进行文件复制操作。 It is an asynchronous operation, and by doc, it says it returns a location in the response header to check the status of the operation, Now the issue is I need its response header so that I can check the status of file copy operation but every time I am getting 'null' as value, I have tried following code,这是一个异步操作,通过文档,它说它在响应 header中返回一个位置来检查操作的状态,现在问题是我需要它的响应 header 以便我可以检查文件复制操作的状态,但是每个当我将'null'作为值时,我尝试了以下代码,

DriveItem response = await graphClient.Sites[siteId].Drive.Items[itemId]
                           .Copy(fileName, parentReference)
                           .Request()
                           .PostAsync();

The driveItem returns null but I think at least it should have returned the additional data-carrying response status and location. driveItem 返回 null 但我认为至少它应该返回额外的数据承载响应状态和位置。

When I use online graph api it just works fine returning response and location, but it doesn't with graph client service.当我使用在线图形 api时,它可以正常返回响应和位置,但它不适用于图形客户端服务。

Apparently it is an issue with msgraph-sdk-dotnet , at least it could be reproduced in 3.8.0 version, the error occurs while d eserializing HTTP response .显然这是msgraph-sdk-dotnet的问题,至少它可以在3.8.0版本中重现,在反序列化 HTTP 响应时发生错误。 Probably it would be more beneficial to report it as a bug in referenced repository.将其报告为引用存储库中的错误可能会更有益。

Meanwhile you could consider to construct a request for Copy a DriveItem endpoint and process response (including extracting Location header) as demonstrated below:同时,您可以考虑构造一个Copy a DriveItem端点的请求并处理响应(包括提取Location标头),如下所示:

var message = graphClient.Sites[siteId].Drive.Items[itemId]
                .Copy(fileName, parentReference)
                .Request()
                .GetHttpRequestMessage();

message.Method = HttpMethod.Post;
var body = new DriveItemCopyRequestBody {Name = fileName, ParentReference = parentReference};
message.Content = new StringContent(graphClient.HttpProvider.Serializer.SerializeObject(body));
message.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = graphClient.HttpProvider.SendAsync(message).Result;
           
Console.Write(response.Headers.Location);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法获取部门名称、经理名称并仅在 Microsoft Graph 中获取有限的用户响应 API C# - Unable to get Department Name ,Manager Name and getting only limited users in response In Microsoft Graph API C# C# 微软图表 Api Request_BadRequest - C# Microsoft Graph Api Request_BadRequest 如何从带有 C# 的 API 中的请求中获取 Header - How to get the Header from a request in a API with C# "在 c# 中使用 Microsoft Graph API 获取所有电子邮件" - Get all email message using Microsoft Graph API in c# 如何使用 Microsoft Graph API 获取 excel 图表的图像? 来自 C# - How do I get the image of an excel chart using Microsoft Graph API ? from c# Microsoft Graph Rest API:如何从 C# 中的 ItemAttachment 获取 MIME 内容 - Microsoft Graph Rest API: How to get MIME-Content from an ItemAttachment in C# 如何在Microsoft Graph API C#中获取用户ID和访问令牌 - How to get User Id and Access Token in Microsoft Graph API C# 如何使用 Microsoft Graph 获取 DriveItem 上的 Sharepoint ListItem - How to get Sharepoint ListItem on DriveItem with Microsoft Graph API c# SDK 如何从 Microsoft Graph API C# 中的 email 地址获取用户 ID - How to get user id from email address in Microsoft Graph API C# c# 如何使用 Microsoft Graph API 获取 Office 365 用户照片 - c# how to get office 365 user photo using microsoft graph api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM