Такого поведения не происходит при подключении к Wi-Fi, где приложение работает корректно. Проблема наблюдалась в одном и том же физическом месте и у разных операторов мобильной связи, в то время как в других приложениях такая же проблема в аналогичных условиях не возникает.
В журналах ошибок исключений не отображается, что позволяет предположить, что проблема может быть связана с задержкой сети или прерывистым подключением, не достигающим порогового значения, вызывающего тайм-аут в приложении.
Код: Выделить всё
public static async Task GenerarQR(string token, string llave, string tipoQR)
{
try
{
var url = $"{Config.Active.APISIAccessQR}/{token}/{llave}/{tipoQR}";
//Se envia headers personalizados a la petición para que no se utilicen los predeterminados
var headers = new Dictionary()
{
["Accept"] = "application/json"
};
var response = await HandlingWebRequestsAsync(HttpMethod.Get, url, headers: headers);
if (response == null)
{
SendException.EnvioError(new Exception(), $"Respuesta NULA por parte del API Siaccess");
return "N/E_QR";
}
if(string.IsNullOrEmpty(response.CodigoQR))
{
SendException.EnvioError(new Exception(), $"Respuesta VACIA/NULA del valor del código de accesso por parte del API Siaccess. VALOR:{response.CodigoQR ?? "NULL"}, URL:{url}");
return "N/E_QR";
}
return response.CodigoQR;
}
catch (Exception ex)
{
SendException.EnvioError(ex, "Ocurrió un problema al generar el QR de la credencial virtual.");
throw;
}
}
Код: Выделить всё
public static async Task HandlingWebRequestsAsync(HttpMethod method, string uri, object body = null, Dictionary headers = null, string otherToken = "")
{
// Verifica si hay conexión a Internet antes de realizar la petición
#if ANDROID || IOS
if (!HasRealInternetAsync())
throw new HttpRequestException("No hay conexión real a Internet.");
#endif
try
{
object response = null;
await GetToken.RefreshToken();
using (var request = CreateWebRequest(method, uri, body, headers, otherToken))
{
response = await HttpClient.SendAsync(request);
}
if (typeof(HttpResponseMessage).IsAssignableFrom(typeof(T)))
{
return (T)response;
}
if (!(response as HttpResponseMessage).IsSuccessStatusCode)
{
return default;
}
//Si no se procede a devolver el contenido deserializado
//Se obtiene el contenido de la respuesta y se transforma a texto para la lectura
var content = await (response as HttpResponseMessage).Content.ReadAsStringAsync();
//Cierra completamente la conexión del HttpClient
(response as HttpResponseMessage).Dispose();
//El contenido se deserealiza para convertirlo en la clase indicada (T)
return JsonConvert.DeserializeObject(content);
}
catch (Exception ex)
{
SendException.EnvioError(ex, "Ocurrió un problema al consumir la Api" + uri + " al parecer no tiene conectividad.");
return default;
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... pplication
Мобильная версия