Daniel
Daniel

Reputation: 1494

How to increase the request timeout?

How do I increase the TimeOut for Get or GetTaskAsync? (Using Facebook C# SDK 6)

Seems like they have a timeout of 15 seconds.

Upvotes: 1

Views: 918

Answers (2)

Collin Dauphinee
Collin Dauphinee

Reputation: 13993

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);

Upvotes: 0

prabir
prabir

Reputation: 7794

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);

Upvotes: 5

Related Questions