title: How to read header data from a web API response in .NET Core?
body: <p>I am calling the web API methods from my client project and returning the value from response header to client:</p>
  <pre class="lang-cs prettyprint-override"><code>[HttpPost]
  [AllowAnonymous]
  [Route(&quot;login&quot;)]
  public IActionResult Login(Users user)
  {
      string s = _repository.Users.ValidateUser(user);
      if (s == &quot;success&quot;)
      {
          Users u = _repository.Users.FindByUserName(user.UserName);
          int pid = u.PersonId;
          string role = &quot;&quot;;
          if (u != null)
          {
  
              role = _repository.RoleManager.GetRole(u.Id);
          }
          Response.Headers.Add(&quot;Role&quot;, role);
          return Ok(pid.ToString());
      }
  
  }
  </code></pre>
  <p>And I tried the code below for getting header value in the client application:</p>
  <pre class="lang-cs prettyprint-override"><code>[HttpPost]
  public IActionResult Login(Users user)
  {    
      string pid = &quot;&quot;;
      HttpClient client = service.GetService();
      HttpResponseMessage response = client.PostAsJsonAsync(&quot;api/mymethod&quot;, user).Result;
      Task&lt;string&gt; tokenResult = response.Content.ReadAsAsync&lt;string&gt;();
      pid = tokenResult.Result.ToString();
         
      var headers = response.Headers;
      string role = &quot;&quot;;
      if (headers.TryGetValues(&quot;Role&quot;, out IEnumerable&lt;string&gt; headerValues))
          {
              role = headerValues.ToString();
          }
  
      return RedirectToAction(&quot;Profile&quot;);
  }
  </code></pre>
  <p>But it returns <code>System.String[]</code> .</p>
  <p>Please show me the right way for fetching data from the response header.</p>