C# 处理来自Microsoft Graph的照片响应
我不知道这个调用实际返回了什么,以及如何在HTML中将它显示为C# 处理来自Microsoft Graph的照片响应,c#,azure-active-directory,microsoft-graph-api,C#,Azure Active Directory,Microsoft Graph Api,我不知道这个调用实际返回了什么,以及如何在HTML中将它显示为img标记。当我使用在线Microsoft Graph Explorer测试环境使用相同的URI时,我得到了预期的图像 var requestUri = "https://graph.microsoft.com/v1.0/barfoo.onmicrosoft.com/users/xxxxx-xxxxxx-xxxxx/photo/$value"; var request = new HttpRequestMessage
img
标记。当我使用在线Microsoft Graph Explorer测试环境使用相同的URI时,我得到了预期的图像
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);
获得用户照片响应后,您应该能够按照以下线条渲染图像:
src=“data:image/jpeg;base64,{{user.profilePic}}”
HttpClient
可以作为流提供响应
在ASP.NET Core中,我使用以下工具完成了此操作:
[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");
}
我想在这之前我有麻烦。SendAsync(请求)返回HttpResponseMessage是否正确?我如何从中获得照片或博客?
<img src="/Home/ProfilePhoto"/>