Код: Выделить всё
public static async Task ProcessWebRequest(string url, T req,ILog Logger, int timeoutInSeconds = 0)
{
var obj = new GenerricApiResponse();
try
{
using (var client = new HttpClient())
{
var jsonRequest = JsonSerializer.Serialize(req);
client.DefaultRequestHeaders.ExpectContinue = false;
var content = new StringContent(jsonRequest);
content.Headers.Clear();
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
if (timeoutInSeconds > 0)
{
client.Timeout = new TimeSpan(0, 0, timeoutInSeconds);
}
var response = await client.PostAsync(url, content);
obj.HttpResponseCode = response.StatusCode;
try
{
string responsecontent = null;
responsecontent = response.Content.ReadAsStringAsync().Result;
if (response.Content != null && response.Content.Headers != null)
{
obj.ResponseContentType = response.Content.Headers.ContentType.MediaType;
if (responsecontent != null && obj.ResponseContentType == "text/html")
{
if (responsecontent != null && responsecontent.Length > 1000)
{
responsecontent = responsecontent.Substring(0, 1000) + "...";
}
}
}
obj.Response = responsecontent;
}
catch
{
obj.IsError = true;
}
}
}
catch (Exception ex)
{
if (ex.InnerException is TimeoutException)
{
ex = ex.InnerException;
}
obj.IsError = true;
obj.Exception = ex;
obj.Response = ex.Message;
}
return obj;
}
System.Net.Http.HttpRequestException: ошибка при копировании содержимого в поток. ---> System.IO.IOException: ответ завершился преждевременно.
Есть идеи, чего не хватает в моем коде или что я делаю не так?< /p>
Все еще понимаю. Даже у меня прошло 90 секунд тайм-аута, но никакого эффекта.
Странно, какое-то время это работало
Подробнее здесь: https://stackoverflow.com/questions/602 ... o-a-stream