I spent 3 days reading all the articles related here and on other websites, about this error, without success! Now I need help.
ERROR:
{StatusCode: 415, ReasonPhrase: 'Unsupported Media Type', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:{
...server's informations...
Strict-Transport-Security: max-age=2592000
X-Android-Received-Millis: 1551400026958
X-Android-Response-Source: NETWORK 415X-
Android-Selected-Protocol: http/1.1
X-Android-Sent-Millis: 1551400026857
X-Powered-By: ASP.NETContent-Length: 0}}
METHOD: The problem appear in: request.PostAsync(URL, param).GetAwaiter().GetResult();
public static string RegisterPerson(Person p)
{
string msg = "";
string URL = URLbase + "person/register"; //--URL RIGHT, TESTING IN POSTMAN, INSERT DATA NORMALLY
FormUrlEncodedContent param = new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("Name", p.Name),
new KeyValuePair<string, string>("Phone", p.Fone),
new KeyValuePair<string, string>("Birth", p.Birth),
});
HttpClient request = new HttpClient();
request.DefaultRequestHeaders.Accept.Clear();
request.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = request.PostAsync(URL, param).GetAwaiter().GetResult(); // <===ERROR HERE
switch (response.StatusCode)
{
case HttpStatusCode.OK:
msg= "SUCCESS";
break;
....
Thank you in advance!
MediaTypeWithQualityHeaderValueof json and not sending json data. Also useawaitinstead of.GetAwaiter().GetResult(), another deadlock just waiting to happen... - SushiHangoverHttpClient request = new HttpClient();is a sure-fire way to use up all of the available system sockets if you callRegisterPersonoften. - Llama