【问题标题】:C# code to allow Proxy access (to get Google API C# example working)允许代理访问的 C# 代码(使 Google API C# 示例工作)
【发布时间】:2026-01-03 08:40:02
【问题描述】:

是否有人能够帮助了解如何让这个 C# 示例通过我的代理服务器工作。我注意到http://code.google.com/apis/gdata/articles/proxy_setup.html#dotnet 有一个代码示例,它提供了一些方向,但是我在如何将其应用于 DocListExporter 示例方面遇到了麻烦。换句话说:

如何在此处应用代码概念(使用代理):

  CalendarService service = new CalendarService("CalendarSampleApp");
  GDataRequestFactory requestFactory = (GDataRequestFactory)
  service.RequestFactory;
  WebProxy myProxy = new WebProxy("http://my.proxy.example.com:3128/",true);
  // potentially, setup credentials on the proxy here
  myProxy.Credentials = CredentialCache.DefaultCredentials;
  myProxy.UseDefaultCredentials = true;
  requestFactory.Proxy = myProxy;

示例中的以下代码:

           GoogleClientLogin loginDialog = new GoogleClientLogin(new DocumentsService("GoogleDocumentsSample"), "youremailh...@gmail.com");
            if (loginDialog.ShowDialog() == DialogResult.OK)
            {
                RequestSettings settings = new RequestSettings("GoogleDocumentsSample", loginDialog.Credentials);
                settings.AutoPaging = true;
                settings.PageSize = 100;
                if (settings != null)
                {
                    this.request = new DocumentsRequest(settings);
                    this.Text = "Successfully logged in";

                    Feed<Document> feed = this.request.GetEverything();
                    // this takes care of paging the results in
                    foreach (Document entry in feed.Entries)
                    {
                        all.Add(entry);
                    }

另外,如果您知道如何包含实际代理用户名/密码的语法,那也会很酷。

谢谢

【问题讨论】:

    标签: c# .net proxy


    【解决方案1】:

    是否尝试在您的 app.config 文件中设置代理?

    类似的东西 -

    <system.net>
      <defaultProxy enabled="true" useDefaultCredentials="true">
        <proxy/>
        <bypasslist/>
        <module/>
      </defaultProxy>
    </system.net>
    

    【讨论】:

    • 不 - 所以感谢您强调这种方法 - 如果它不工作,这似乎是一个更好的方法?也就是说,人们不必担心如何以编程方式实现以他们使用 .net HTTP 类的方式融入 Google 客户端库的结果。使用这种声明性方法有什么负面影响吗?是否会使在无代理和有代理之间进行交换变得更加困难,例如程序运行在有时但并非总是在代理服务器后面的膝上型电脑上的情况?谢谢