【发布时间】:2016-12-31 05:36:17
【问题描述】:
我正在开发一个具有一些简单功能的基于 .NET 的 Youtube API 客户端。我继续创建这样的服务实例:
youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "",
ApplicationName = "my_wonderful_client"
});
但是,我还需要它能够使用代理来建立连接,所以我继续说:
if (useProxy)
{
Google.Apis.Http.ConfigurableHttpClient customClient = null;
string proxyUri = "http://proxy.proxy.com";
NetworkCredential proxyCreds = new NetworkCredential(
@"domain\user",
"pass123"
);
WebProxy proxy = new WebProxy(proxyUri, 8080)
{
UseDefaultCredentials = false,
Credentials = proxyCreds,
};
HttpClientHandler httpClientHandler = new HttpClientHandler()
{
Proxy = proxy,
PreAuthenticate = true,
UseDefaultCredentials = false,
};
Google.Apis.Http.ConfigurableMessageHandler customHandler = new Google.Apis.Http.ConfigurableMessageHandler(httpClientHandler);
customClient = new Google.Apis.Http.ConfigurableHttpClient(customHandler);
}
现在如何使用我的 customClient 来初始化连接?唉,.NET API 上的文档非常稀缺。
谢谢。
【问题讨论】:
-
Abielita,感谢您的回答。不幸的是,第一种方法与 API 的旧版本有关,而第二种解决方案与使用 API 的原始 HTTP/JSON 通信而无需使用任何库并没有太大区别。我相信,在这样一个复杂的框架中,一定有一些简单的解决方案。
标签: c# proxy youtube-api