Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 处理来自Microsoft Graph的照片响应_C#_Azure Active Directory_Microsoft Graph Api - Fatal编程技术网

C# 处理来自Microsoft Graph的照片响应

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

我不知道这个调用实际返回了什么,以及如何在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(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"/>