本文介绍了处理来自Microsoft Graph的照片响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法弄清楚此调用实际返回的内容以及如何将其显示为HTML中的img
标记.当我在联机Microsoft Graph Explorer测试环境中使用相同的URI时,将获得预期的图像.
I can't figure out what actually is returned by this call and how I can display it in HTML as an img
tag. When I use the same URI using the online Microsoft Graph Explorer test environment I get the image as intended.
var requestUri =
"https://graph.microsoft.com/v1.0/barfoo.onmicrosoft.com/users/xxxxx-xxxxxx-xxxxx/photo/$value";
var request =
new HttpRequestMessage(HttpMethod.Get, requestUri);
var accessToken =
await _authenticationHelper.GetAccessTokenAsync();
request.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", accessToken);
var response = await client.SendAsync(request);
推荐答案
HttpClient
可以为您提供Stream
的响应.
HttpClient
can give you the response as a Stream
.
在ASP.NET Core中,我这样做的是:
In ASP.NET Core, I've done this with:
[HttpGet]
public async Task<IActionResult> ProfilePhoto()
{
//removed all the code which you already have
HttpResponseMessage res = await client.SendAsync(request);
return File(await res.Content.ReadAsStreamAsync(), "image/jpeg");
}
经典" ASP.NET MVC应该完全相同,您至少应将IActionResult
替换为ActionResult
.
"Classic" ASP.NET MVC should be pretty identical, you would replace IActionResult
with ActionResult
at least.
然后您可以将其链接到图像标签,例如:
You can then link this to an image tag like:
<img src="/Home/ProfilePhoto"/>
这篇关于处理来自Microsoft Graph的照片响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!