Hi guys,
I'm having problem executing "PostAsync" as it is giving unusual error, My whole code works fine except the line with "PostAsync". The weird thing is that , it posts the content to the database through PostAsync successfully but then jumps to "Catch" and throws exception. I have given my code below, what am I doing wrong..?
FYI: I'm using Xamarin.Forms and the database is Sharepoint list
try
{
using (var client = new HttpClient()
{ Timeout = TimeSpan.FromSeconds(5) })
using (var content = new MultipartFormDataContent())
{
var values = new[]
{
new KeyValuePair<string, string>("PinCode", pincode),
new KeyValuePair<string, string>("Email", email),
new KeyValuePair<string, string>("FirstName", firstname),
new KeyValuePair<string, string>("MiddleName", middlename),
new KeyValuePair<string, string>("FamilyName", familyname)
};
foreach (var keyValuePair in values)
content.Add(new StringContent(keyValuePair.Value), keyValuePair.Key);
using (var result = await client.PostAsync(requestUri, content).ConfigureAwait(false)) //App Jumps to Catch and don't execute further
{
var input = await result.Content.ReadAsStringAsync().ConfigureAwait(false);
if (result.IsSuccessStatusCode)
{
await DisplayAlert("Response:>", result.StatusCode.ToString(), "OK");
submit.IsEnabled = false;
}
else await DisplayAlert("Response:>", "Unsuccessful", "OK");
}
}
}
catch (TaskCanceledException ex)
{
if (ex.CancellationToken.IsCancellationRequested == false)
{ await DisplayAlert("ex", "Unsuccessful", "OK"); }
else
{ await DisplayAlert("ex", "true~~~~", "OK"); }
}