Exception
あるWebアプリケーションから送信し、別のWebアプリケーションで取得します。HttpRequestException
この場合、どうすれば値を取得できますか?
送信元:
context.Response = new HttpResponseMessage(apiError.StatusCode)
{
Content = new ObjectContent<ApiError>(apiError,
new JsonMediaTypeFormatter(), @"application/json")
};
return context;
別のものに入る:
catch (HttpRequestException e)
{
this.logger.LogError(
string.Format("Ошибка запроса {0}", requestUri.AbsoluteUri),
LogCategoryRepository.ApiCashdesk,
e);
throw;
}
OK。クラスを作成するだけです。
public class ErrorDetails
{
public string Details { get; set; }
}
そしてそれを使用してください:
try
{
using (var response = await client.SendAsync(request).ConfigureAwait(false))
{
if(!response.IsSuccessStatusCode)
{
***var error = await response.Content.ReadAsAsync<ErrorDetails>().ConfigureAwait(false);***
throw new HttpRequestException(error.Details);
}
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadAsAsync<TResponse>().ConfigureAwait(false);
return result;
}
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加