Ahmad Darwish
Ahmad Darwish

Reputation: 91

Facebook SDK Proxy setting C#

I use Facebook SDK .net but I use proxy with authentication to connect to the internet I get the error (407) (407) proxy authentication required how I can set the authentication on Facebook SDK

Upvotes: 6

Views: 2139

Answers (2)

David Clarke
David Clarke

Reputation: 13266

I recently had this issue when using FacebookClient to post to a Facebook page. In my case I have a WCF service that is responsible for the Facebook interactions and the service sits behind a company proxy. This stackoverflow answer resolved the issue for me but requires the IIS app pool user identity for the service to be set to a user that has domain credentials, otherwise the 407 error is returned. So set the app pool identity to a domain account and add the following to web.config:

<system.net>
  <defaultProxy useDefaultCredentials="true" />
</system.net>

Upvotes: 0

prabir
prabir

Reputation: 7794

There is a static method in FacebookClient which allows you to set it globally.

[EditorBrowsable(EditorBrowsableState.Never)]
public static void SetDefaultHttpWebRequestFactory(Func<Uri, HttpWebRequestWrapper> httpWebRequestFactory)

You might not see it in the intellisense as it is hidden by default.

If you want it per instance you can use the property.

[EditorBrowsable(EditorBrowsableState.Never)]
public virtual Func<Uri, HttpWebRequestWrapper> HttpWebRequestFactory { get; set; }

Here is an example.

FacebookClient.SetDefaultHttpWebRequestFactory(uri => {
    var request = new HttpWebRequestWrapper((HttpWebRequest)WebRequest.Create(uri));
    request.Proxy = ......; // normal .net IWebProxy
    return request;
});

Upvotes: 8

Related Questions