how to solve "unexpected end of stream on com.android.okhttp.Address@c4d56f78" in C# xamarin forms android?

Viewed 36

I'm working with C# xamarin forms android and I'm trying to send a json to my web but when I do that my application tells me this error "unexpected end of stream on com.android.okhttp.Address@c4d56f78". This error happens when I try the postasync method.

This is my Page.xaml.cs code:

            string cadena = "this is my string";
            
            using (var client = new HttpClient())
            {
                var contentType = new MediaTypeWithQualityHeaderValue("application/json");
                var baseAddress = "url.com";
                client.BaseAddress = new Uri(baseAddress);
                client.DefaultRequestHeaders.Accept.Add(contentType);

                var data = new Dictionary<string, string>
                {
                        {"cadena", cadena},
                 };

                var jsonData = JsonConvert.SerializeObject(data);
                var contentData = new StringContent(jsonData, Encoding.UTF8, "application/json");

                var response = await client.PostAsync(baseAddress, contentData);
                string res = await response.Content.ReadAsStringAsync();
                await DisplayAlert("Respuesta", res, "OK");
            }

How could I resolve this?

Thank you very much!

0 Answers
Related