.Net Core 服务 HTTPClient 调用不一致地返回错误请求

.Net Core Service HTTPClient Call Inconsistently Returning Bad Request

我有一个 .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

这个问题是因为我在循环中无休止地添加默认请求 headers。在添加默认值之前,我更改了代码以清除请求 headers,现在服务运行正常。