` public async Task ValidateUser(string username, string password)
{
//Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var m = new UserModel { user = new List<user> { new user{username = username, password=password} } }; var Sercontent = JsonConvert.SerializeObject(m); //var content = new StringContent(Sercontent, Encoding.UTF8, "application/json"); //var response = await Client.PostAsync(URL, content).ConfigureAwait(false); //breaks here //if (response.IsSuccessStatusCode) // return await response.Content.ReadAsStringAsync(); //return null; var http = (HttpWebRequest)WebRequest.Create(new Uri(URL2)); http.Accept = "application/json"; http.ContentType = "application/json"; http.Method = "POST"; UTF8Encoding enc = new UTF8Encoding(); Byte[] bytes = enc.GetBytes(Sercontent); using (var stream = await Task.Factory.FromAsync<Stream>(http.BeginGetRequestStream, http.EndGetRequestStream, null)) //breaks here { stream.Write(bytes, 0, bytes.Length); stream.Dispose(); } using (var response = (HttpWebResponse)await Task.Factory.FromAsync<WebResponse>(http.BeginGetResponse, http.EndGetResponse, null)) { var responseStream = response.GetResponseStream(); var sr = new StreamReader(responseStream); var content = sr.ReadToEnd(); return content; }
}`
The app gets unhandled exception, idk why, I have tried this using console app and it works magically, only using xamarin forms makes it hard.
I am also using .svc as web service but yea we treat it as http web.
Fixed. The webservice I tried to fetch is not accessible through mobile/emulator, also I did not use httpclient for this (it doesn't work in my case) but rather I used HttpWebRequest.
Answers
Fixed. The webservice I tried to fetch is not accessible through mobile/emulator, also I did not use httpclient for this (it doesn't work in my case) but rather I used HttpWebRequest.