title: API GET Request Returns HTML/Text instead of JSON
body: <p>This is my first time working with a RESTful API and Xamarin and etc. I have so far made a simple REST API. I have written a GET call to it that, if I write <a href="http://localhost:[num]/api/Name" rel="nofollow noreferrer">http://localhost:[num]/api/Name</a>, it will return a JSON file of the matching Emu's information. I have tested this with Postman, so I know that it works. </p>
  
  <p>I have now written an app that will call this API in order to catch this information and then display it. So far, I've got it connected to the server hosting my API, but I'm unable to get it to return JSON. Instead it seems to be returning text/HTTP.</p>
  
  <p>From what I've searched up on previous Stack Overflow threads, it seems that I was missing Headers requesting that reply be in a JSON format. When I added in code that was on the official .NET documentation on Microsoft's website, it gave me issues with my Json Deserialiser. I have also added in the information in the header to make sure that it returns json.</p>
  
  <p>Here is the code for the function:</p>
  
  <pre><code>async private void Submit_OnClicked(object sender, EventArgs e)
          {
              var nameValue = EmuName.Text;
  
              var baseAddr = new Uri("http://my_url/HelloEmu/");
              var client = new HttpClient { BaseAddress = baseAddr };
              client.DefaultRequestHeaders.Accept.Clear();
              client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
              string url = (string)nameValue;
              var returnedJson = await client.GetStringAsync(url);
  
              Models.EmuItemModel MyEmu = JsonConvert.DeserializeObject&lt;Models.EmuItemModel&gt;(returnedJson);
  
  
              ReturnedName.Text = MyEmu.Name;
              ReturnedAge.Text = MyEmu.Age.ToString();
              ReturnedWeight.Text = MyEmu.Weight.ToString();
  </code></pre>
  
  <p>My code actually faults on the line <code>ReturnedWeight.Text = MyEmu.Weight.ToString()</code>
  But I'm guessing the more majour issue is occuring during deserialisng the object, because it seemingly "skips" over the preceeding two lines when I run it in the debugger.</p>
  
  <p>When I run it in Visual Studio 2019, the value of "returnedJson" is this:</p>
  
  <pre><code>"&lt;html&gt;&lt;head&gt;&lt;meta http-equiv=\"refresh\" content=\"0;url=http://lookup.t-mobile.com/search/?q=http://my_url/HelloEmu/Keith&amp;t=0\"/&gt;&lt;/head&gt;&lt;body&gt;&lt;script&gt;window.location=\"http://lookup.t-mobile.com/search/?q=\"+escape(window.location)+\"&amp;r=\"+escape(document.referrer)+\"&amp;t=0\";&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;" 
  </code></pre>
  
  <p>I <em>think</em> this is an HTML output. I would love any hints about what on earth I'm doing wrong!</p>
  
  <p>EDIT: Since it almost seems like the HTML is returning an error message, perhaps it could do with my url??? I've published the website using the File system method. So to access the API in Postman I'll use <a href="http://localhost:[port]/api/values" rel="nofollow noreferrer">http://localhost:[port]/api/values</a>, calling my website in a regular ol' browser makes it go <a href="http://my_url/HelloEmu" rel="nofollow noreferrer">http://my_url/HelloEmu</a>. I get a 403 "no directory" method in return...</p>
  
  <p>EDIT: Here is the Postman code:
  <a href="https://i.stack.imgur.com/a9ZqA.png" rel="nofollow noreferrer">enter image description here</a></p>