Friday 12 January 2018

C# UWA StatusCode: 415, ReasonPhrase: 'Unsupported Media Type'

Error: StatusCode: 415, ReasonPhrase: 'Unsupported Media Type'

Root cause:

        var jsonContent = JsonConvert.SerializeObject(InputContent);
       StringContent content = new StringContent(jsonContent );

       var result = await client.PostAsync("http://localhost/MyAPI/api/login", content);

content is not having right media type

Solution:

format content to right media type

  var jsonContent = JsonConvert.SerializeObject(InputContent);
       StringContent content = new StringContent(jsonContent ,Encoding.UTF8, "application/json"); 

       var result = await client.PostAsync("http://localhost/MyAPI/api/login", content);