redcap-api
redcap-api copied to clipboard
configured HttpClient.Timeout
I'm making a large Import request and sometimes I see the following error:
The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.
Is there anywhere in this package where we can increase the timeout?
Thanks
Here's a possible way to do this:
/// <summary>
/// Sends request using http
/// </summary>
/// <param name="redcapApi"></param>
/// <param name="payload">data</param>
/// <param name="uri">URI of the api instance</param>
/// <param name="cancellationToken"></param>
/// <param name="timeOutSecs"></param>
/// <returns></returns>
public static async Task<string> SendPostRequestAsync(this RedcapApi redcapApi,
Dictionary<string, string> payload,
Uri uri,
CancellationToken cancellationToken = default,
long timeOutSecs = 100)
{
try
{
string _responseMessage;
TimeSpan tsTimeOut = TimeSpan.FromTicks(timeOutSecs * TimeSpan.TicksPerSecond);
using var handler = GetHttpHandler();
using var client = new HttpClient(handler);
client.Timeout = tsTimeOut;
<snipped>
importRecordsResults
= await this.SendPostRequestAsync(payload, _uri, cancellationToken: cancellationToken, 180L);
@274188A Did you want to make a PR for this? I can also brew up initial draft for you to approve. What do you think? I should have something going by tomorrow.
sure np - kind of busy atm but will get to it
#125 merged 1.3.5 soon