2009-09-18 59 views
1

是否有人能夠幫助理解如何通過我的代理服務器獲取此C#示例。我注意到有一個代碼示例http://code.google.com/apis/gdata/articles/proxy_setup.html#dotnet,它提供了一些指導,但是我在如何將它應用於DocListExporter示例時遇到了問題。換句話說:允許代理訪問的C#代碼(獲得Google API C#示例工作)

我怎麼在這裏申請代碼的概念(有代理):

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"), "[email protected]"); 
      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); 
        } 

此外,如果你知道的語法如何包含實際的代理用戶名/密碼,這也會很酷。

感謝

回答

2

是否嘗試建立在你的app.config文件的代理?

這樣的事情 -

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

沒有 - 所以感謝強調這種做法 - 這似乎更好的方式來做到這一點,如果它工作沒有?也就是說,人們不必擔心如何以編程方式實現以他們使用.net HTTP類的方式實現將結果插入到Google客戶端庫中的結果。 使用這種說明性方法有什麼不利嗎?會不會讓代理和代理之間交換更困難,比如說程序運行在可能位於代理服務器後面的膝上型計算機上,但有時候並不總是如此? 謝謝 – Greg 2009-09-19 03:36:05