Skip to content

Commit 6f9b397

Browse files
authored
Merge pull request #1 from univteam/improve
fix httpclient problems
2 parents 90ef2f5 + ab37edb commit 6f9b397

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Request/ServiceCaller.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ public async Task<HttpResponseMessage> CallServiceAsync(ServiceRequest serviceRe
3838
// setup headers
3939
//
4040
// 超时时间,毫秒
41-
_client.Timeout = TimeSpan.FromMilliseconds(_requestContext.ClientConfiguration.ConnectionTimeout);
41+
//httpclient 默认100s
42+
// httpclient的 BaseAddress TimeOut MaxResponseContentBufferSize 属性 只能被设置一次
43+
//第二次设置就会出现异常:
44+
//“This instance has already started one or more requests.
45+
// Properties can only be modified before sending the first request.”
46+
if (_requestContext.ClientConfiguration.ConnectionTimeout != -1)
47+
_client.Timeout = TimeSpan.FromMilliseconds(_requestContext.ClientConfiguration.ConnectionTimeout);
4248
foreach (var h in serviceRequest.Headers)
4349
{
4450
bool rtn = request.Headers.TryAddWithoutValidation(h.Key, h.Value);

0 commit comments

Comments
 (0)