问题
How do I increase the TimeOut for Get or GetTaskAsync? (Using Facebook C# SDK 6)
Seems like they have a timeout of 15 seconds.
回答1:
Use FacebookClient.HttpWebRequestFactory. Since it is hidden from intellisense you might not see it in VS depending on your settings.
/// <summary>
/// Http web request factory.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual Func<Uri, HttpWebRequestWrapper> HttpWebRequestFactory
{
get; set;
}
You might want to do something like this.
FacebookClient.HttpWebRequestFactory = url => {
var request = new HttpWebRequestWrapper((HttpWebRequest)WebRequest.Create(url));
request.Timeout = .....;
return request;
};
This requires v6 at minimum.
for v5, you need to override a protected method.
/// <summary>
/// Creates the http web request.
/// </summary>
/// <param name="url">The url of the http web request.</param>
/// <returns>The http helper.</returns>
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
protected virtual HttpWebRequestWrapper CreateHttpWebRequest(Uri url);
回答2:
For the GetTaskAsync
version, you need to pass a cancellation token. The Timeout
value set on the request is not honored.
var cancellationSource = new CancellationTokenSource(TimeSpan.FromSeconds(2));
await client.GetTaskAsync<T>(path, parameters, cancellationSource.Token);
来源:https://stackoverflow.com/questions/10924610/how-to-increase-the-request-timeout