当前位置: 首页>>代码示例>>C#>>正文


C# RestClient.AddField方法代码示例

本文整理汇总了C#中RestClient.AddField方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.AddField方法的具体用法?C# RestClient.AddField怎么用?C# RestClient.AddField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RestClient的用法示例。


在下文中一共展示了RestClient.AddField方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Post_Click

        /**
         * Actually post the image... finally.
         **/
        private void Post_Click(object sender, EventArgs e)
        {
            // Check if we have credentials
            IsolatedStorageSettings storage = IsolatedStorageSettings.ApplicationSettings;

            // If we have no credentials, force the user to enter their info in account settings.
            if (!storage.Contains("userCredentials"))
            {
                NavigationService.Navigate(new Uri("/AccountSettingsPage.xaml", UriKind.Relative));
            }
            else
            {
                // Get the credentials
                TumblrCredentials userCredentials = storage["userCredentials"] as TumblrCredentials;

                // We have credentials, do we have a photo?
                if (photo != null)
                {
                    // Now here comes the POST!

                    // Create a RestClient
                    RestClient client = new RestClient();
                    client.Authority = MainPage.TUMBLR_AUTHORITY;
                    client.HasElevatedPermissions = true;

                    client.Path = MainPage.TUMBLR_POST_PATH;
                    client.Method = Hammock.Web.WebMethod.Post;

                    // Set the correct credentials on the client or request depending on auth method
                    if (userCredentials.Type == TumblrCredentials.CredentialsType.OAuth)
                    {
                        OAuthCredentials oAuthCred = new OAuthCredentials();
                        oAuthCred.ConsumerKey = Common.OAUTH_CONSUMER_KEY;
                        oAuthCred.ConsumerSecret = Common.OAUTH_CONSUMER_SECRET;
                        oAuthCred.Token = userCredentials.OAuthToken;
                        oAuthCred.TokenSecret = userCredentials.OAuthTokenSecret;
                        oAuthCred.ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader;
                        oAuthCred.SignatureMethod = OAuthSignatureMethod.HmacSha1;
                        oAuthCred.Type = OAuthType.ProtectedResource;

                        client.Credentials = oAuthCred;
                    }
                    else
                    {
                        client.AddField("email", userCredentials.Username);
                        client.AddField("password", userCredentials.Password);
                    }

                    // Add metadata fields
                    client.AddField("type", "photo");
                    //client.AddField("state", "draft"); // Debug line for testing
                    client.AddField("send-to-twitter", "auto"); // Debug line because I'm paranoid

                    // Add caption but check for an empty field
                    if (!this.hasDefaultText)
                    {
                        client.AddField("caption", this.captionTextbox.Text);
                    }

                    client.AddFile("data", "upload.jpg", new MemoryStream(photo));

                    // Send the request of to la-la-land
                    client.BeginRequest(new RestCallback(PostCompleted));

                    this.isPosting = true;
                    // HACK: Well this is hacky...
                    Dispatcher.BeginInvoke(() => ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = false);

                    Dispatcher.BeginInvoke(() =>
                    {
                        this.postProgress.Visibility = System.Windows.Visibility.Visible;
                        this.captionTextbox.IsEnabled = false;
                        this.postProgress.Focus();
                    });
                }
                else
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show("Please Select a Photo."));
                }
            }
        }
开发者ID:tmrudick,项目名称:wp7-tumblr-photo-uploader,代码行数:84,代码来源:MainPage.xaml.cs


注:本文中的RestClient.AddField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。