Facebook SDK Proxy setting C#

感情迁移 提交于 2019-12-10 04:22:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!