[英]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.