private async Task GetResponseCallback(Task<WebResponse> task)
{
// get the response
HttpWebResponse response;
try
{
response = (HttpWebResponse)await task.ConfigureAwait(false);
}
catch (Exception e)
{
if (e.InnerException != null && e.InnerException.Message.StartsWith("[net_WebHeaderInvalidControlChars]"))
{
// not an exception, everything is ok
this.InvokeInUiThread(() => this.OnCompleted(null));
}
else
{
this.InvokeOnErrorHandler(ErrorMessages.HttpPostError);
}
return;
}
if (response.StatusCode != HttpStatusCode.OK)
{
this.InvokeOnErrorHandler((int)response.StatusCode + " " + response.StatusDescription);
return;
}
// response stream
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
string str = reader.ReadToEnd();
this.InvokeInUiThread(() => this.OnCompleted(str));
}
}
}