问题
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
回答1:
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;
});
回答2:
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>
来源:https://stackoverflow.com/questions/12251150/facebook-sdk-proxy-setting-c-sharp