title: Returning JSON via WebApi
body: <p>I am using the HttpClient in C# to try and integrate SSO (Single Sign On) into some of our custom Applications.</p>
  
  <p>I have done this successfully in our JavaScript Apps, but I'm having some difficulty integrating it into some of our Umbraco sites.</p>
  
  <p>My code so far:</p>
  
  <pre><code>using System;
  using System.Threading.Tasks;
  using System.Net.Http;
  using System.Net.Http.Headers;
  using System.Web;
  using System.Web.Http;
  using Newtonsoft.Json;
  using System.Collections.Generic;
  using Umbraco.Web;
  using Umbraco.Web.WebApi;
  
  namespace Umbraco.WebApi
  {
    public class TestController : UmbracoApiController
    {
  
      public  HttpClient client = new HttpClient();
  
      [HttpPost]
      public async Task&lt;Object&gt; GetRefreshToken(Token t)
      {
        try {
          string refToken = t.refresh_token;
  
          var values = new Dictionary&lt;string, string&gt;
          {
            { "grant_type", "refresh_token" },
            { "client_id", "CLIENTID" },
            { "client_secret", "CLIENTSECRET" },
            { "refresh_token", refToken }
          };
  
          var content = new FormUrlEncodedContent(values);        
          var response = await client.PostAsync("https://URL.org/Token", content);
  
          string responseString = await response.Content.ReadAsStringAsync();
  
          return responseString;
  
        } catch(HttpRequestException e) {
          return e;
        }
      }
  
      public class Token
      {
        public string refresh_token { get; set; }
      }
  
      public class AuthData
      {
        public string access_token { get; set; }
        public string token_type { get; set; }
        public int expires_int { get; set; }
        public string refresh_token { get; set; }
        public string userName { get; set; }
        public string client_id { get; set; }
        public DateTime issued { get; set; }
        public DateTime expires { get; set; }
  
      }
    }
  }
  </code></pre>
  
  <p>Which does successfully return the data I'm after but there are issues with the returned data (Removed sensitive data):</p>
  
  <pre><code>&lt;z:anyType xmlns:d1p1="http://www.w3.org/2001/XMLSchema" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" i:type="d1p1:string"&gt;
  {"access_token":"XXXXXXXX","token_type":"bearer","expires_in":1199,"refresh_token":"XXXXXX","userName":"XXXXXX","as:client_id":"XXXXX",".issued":"Fri, 20 Sep 2019 13:23:48 GMT",".expires":"Fri, 20 Sep 2019 13:43:48 GMT"}
  &lt;/z:anyType&gt;
  </code></pre>
  
  <p>It also seems to be getting returned as XML instead of JSON?</p>
  
  <p>C# is not my strongest of languages, so I may be completely wrong.</p>
  
  <p>Any help appreciated.</p>