我有一个.net核心服务作为应用程序服务运行。以下调用每5秒运行几小时,然后该服务开始出现400错误。如果我启动和停止该服务,则该应用程序将开始正常运行。
_httpClient.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true };
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
string utcDateOut = DateTime.UtcNow.ToString("s", CultureInfo.InvariantCulture);
var sURI = _arlnPortalBaseUrl + _arlnPortalSvcDownloads + "?$filter=downloadRequestStatus ne 'Completed' and downloadRequestStatus ne 'Failed'&timeStamp=" + utcDateOut ;
var downloadResponse = await _httpClient.GetAsync(new Uri(sURI));
日志显示有关HTTP客户端请求的以下信息。
2019-12-20 12:12:48.2109|100|INFO|System.Net.Http.HttpClient.Default.ClientHandler|Sending HTTP request GET http://10.32.1.132/arln-portal-service/odata/Downloads?$filter=downloadRequestStatus ne 'Completed' and downloadRequestStatus ne 'Failed'&timeStamp=2019-12-20T17:12:48 |url: |action:
2019-12-20 12:12:48.2282|101|INFO|System.Net.Http.HttpClient.Default.ClientHandler|Received HTTP response after 10.6963ms - BadRequest |url: |action:
2019-12-20 12:12:48.2282|101|INFO|System.Net.Http.HttpClient.Default.LogicalHandler|End processing HTTP request after 19.1219ms - BadRequest |url: |action:
2019-12-20 12:12:48.2282||ERROR|arln_sqs_service.Worker|Issue connecting to the ArlnPortalService at: http://10.32.1.132/arln-portal-service/odata/Downloads?$filter=downloadRequestStatus ne 'Completed' and downloadRequestStatus ne 'Failed'&timeStamp=2019-12-20T17:12:48. StatusCode is not 200. Unable to query the pending downloads. downloadResponse Status Code: BadRequest |url: |action:
2
该问题是由于我无休止地在循环中添加默认请求标头而引起的。我更改了代码,以在添加默认值之前清除请求标头,并且该服务现在可以正常运行。