【发布时间】:2021-09-01 17:10:25
【问题描述】:
这就是我正在尝试的:
public static async Task<HttpResponseMessage> post(string specificUrl, string token, StringContent inputData) // specificUrl like "user/" at the end "/"
{
var policy = Policy
.Handle<Exception>()
.OrResult<HttpResponseMessage>(res => !res.IsSuccessStatusCode)
.RetryAsync(3);
string fullUrl = baseUrl + specificUrl;
using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, fullUrl))
{
requestMessage.Content = inputData;
requestMessage.Headers.Add("access_token", token);
//HttpResponseMessage res = await client.SendAsync(requestMessage).ConfigureAwait(false);
HttpResponseMessage res = await policy.ExecuteAsync(() => client.SendAsync(requestMessage)).ConfigureAwait(false);
return res;
}
}
只要代码达到 waitAndRetryPolicy 并等待所需的时间,我就会收到以下错误:
System.InvalidOperationException: '请求消息已经发送。不能多次发送相同的请求消息。
【问题讨论】:
标签: c#