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


C# RestRequest.AddFile方法代码示例

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


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

示例1: ApplicationBarIconButton_Click

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            RestClient client2 = new RestClient
            {
                Authority = "https://graph.facebook.com/",
            };

            RestRequest request2 = new RestRequest
            {
                Path = "/me/feed?message=" + WatermarkTB.Text
            };
            if (imgstream != null)
            {
                string albumId = (string)settings["facebook_photo"];
                request2 = new RestRequest
                {
                    Path = albumId + "/photos?message=" + WatermarkTB.Text
                };
                request2.AddFile("photo", "image.jpg", imgstream);
            }
            request2.AddField("access_token", (string)settings["facebook_token"]);
            var callback = new RestCallback(
                (restRequest, restResponse, userState) =>
                {
                    // Callback when signalled
                }
                );
            client2.BeginRequest(request2, callback);

            MessageBox.Show("Share successfully.", "Thanks", MessageBoxButton.OK);
            this.NavigationService.GoBack();
        }
开发者ID:vapps,项目名称:HDStream,代码行数:32,代码来源:FacebookWrite.xaml.cs

示例2: ApplicationBarIconButton_Click

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            string auth_key = String.Format("full_auth_token {0}", settings["me2day_token"]);
            IWebCredentials credentials = new BasicAuthCredentials
            {
                Username = (string)settings["me2day_userid"],
                Password = auth_key
            };

            RestClient client = new RestClient
            {
                Authority = "http://me2day.net/api/"
            };

            RestRequest request = new RestRequest
            {
                Credentials = credentials,
                Path = String.Format("create_post/{0}.xml?akey=aed420d038f9b1a7fe3b5c0d94df22f5", settings["me2day_userid"])
            };
            request.AddParameter("post[body]", WatermarkTB.Text);
            request.AddParameter("post[tags]", WatermarkTB2.Text);

            if (imgstream != null)
            {
                request.AddFile("attachment", "image.jpg", imgstream, "image/jpeg");
            }

            var callback = new RestCallback(
                (restRequest, restResponse, userState) =>
                {
                    // Callback when signalled
                }
            );

            client.BeginRequest(request, callback);

            MessageBox.Show("Share successfully.", "Thanks", MessageBoxButton.OK);
            this.NavigationService.GoBack();
        }
开发者ID:vapps,项目名称:HDStream,代码行数:39,代码来源:Me2dayWrite.xaml.cs

示例3: photoChooserTask_Completed

        private void photoChooserTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                img_bool = true;
                var client = new RestClient
                {
                    Authority = "http://api.twipl.net/",
                    VersionPath = "1",
                };

                var request = new RestRequest
                {
                    Path = "upload.json" // can be upload.xml or whatever, but you have to parse it accordingly
                };

                request.AddFile("media1", "img.jpg", e.ChosenPhoto);
                request.AddField("key", "b76ecda29f7c47e0bfefd0b458e91fb5");
                request.AddField("oauth_token", (string)settings["twitter_token"]);
                request.AddField("oauth_secret", (string)settings["twitter_tokensecret"]);
                request.AddField("message", "");
                 client.BeginRequest(request, new RestCallback(Callback));

             }
        }
开发者ID:vapps,项目名称:HDStream,代码行数:25,代码来源:TwitterWrite.xaml.cs

示例4: ShareOnTwitter

        //void fb_PostCompleted(object sender, FacebookApiEventArgs e)
        //{

        //    if (e.Error != null)
        //    {
        //        Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
        //        return;
        //    }
        //    else
        //    {
        //        Dispatcher.BeginInvoke(() =>
        //        {
        //            progbar1.IsIndeterminate = false;
        //            progbar1.Visibility = Visibility.Collapsed;
        //            MessageBox.Show("Successfully shared on Facebook");
        //            //if (NavigationService.CanGoBack)
        //            //    NavigationService.GoBack();

        //        });

        //    }
        //}


        public  void ShareOnTwitter()
        {
            OAuthCredentials credentials = new OAuthCredentials();

            credentials.Type = OAuthType.ProtectedResource;
            credentials.SignatureMethod = OAuthSignatureMethod.HmacSha1;
            credentials.ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader;
            credentials.ConsumerKey = TwitterSettings.ConsumerKey;
            credentials.ConsumerSecret = TwitterSettings.ConsumerKeySecret;

            credentials.Token = tokenx;
            credentials.TokenSecret = tokensecx;
            credentials.Version = "1.0";
            //credentials.ClientUsername = "";
            //credentials.CallbackUrl = "www.google.com";

            //var service = new TwitterService(TwitterSettings.ConsumerKey, TwitterSettings.ConsumerKeySecret);

            //service.AuthenticateWith(tokenx, tokensecx);

            //var resized = img.Resize(img.PixelWidth / 4, img.PixelHeight / 4, WriteableBitmapExtensions.Interpolation.Bilinear);

            //var fileStream = new MemoryStream();
            //resized.SaveJpeg(fileStream, resized.PixelWidth, resized.PixelHeight, 100, 100);
            //fileStream.Seek(0, SeekOrigin.Begin);

            //SendTweetWithMediaOptions msgMedia = new SendTweetWithMediaOptions();
            //msgMedia.Status = photo_text.Text;
            //Dictionary<string, Stream> imageDict = new Dictionary<string, Stream> { { fileName, fileStream } };
            ////imageDict.Add(imagePath, imageStream);
            //msgMedia.Images = imageDict;
            ////status = service.SendTweetWithMedia(new SendTweetWithMediaOptions() { Status = readerMsg.Message, Images = imageDict });
            //service.SendTweetWithMedia(msgMedia, tweetResponse);


            //other method

            RestClient _client = new RestClient
            {
                Authority = "https://api.twitter.com",
                HasElevatedPermissions = true,

            };

            var twitterRequest = new RestRequest
            {
                Credentials = credentials,
                Path = "/1.1/statuses/update_with_media.json",
                Method = WebMethod.Post
            };

            //twitterRequest.AddHeader("content-type", "application/x-www-form-urlencoded");

            //twitterRequest.AddHeader("content-type", "multipart/form-data");


            //twitterRequest.AddField("consumer_token", TwitterSettings.ConsumerKey);
            //twitterRequest.AddField("consumer_secret", TwitterSettings.ConsumerKeySecret);
            //twitterRequest.AddField("oauth_token", tokenx);
            //twitterRequest.AddField("oauth_secret", tokensecx);



            var resized = img.Resize(img.PixelWidth / 4, img.PixelHeight / 4, WriteableBitmapExtensions.Interpolation.Bilinear);

            var fileStream = new MemoryStream();
            resized.SaveJpeg(fileStream, resized.PixelWidth, resized.PixelHeight, 100, 100);
            fileStream.Seek(0, SeekOrigin.Begin);


            //twitterRequest.AddParameter("status", photo_text.Text);
            twitterRequest.AddField("status", photo_text.Text); 
            twitterRequest.AddFile("media[]", "test", fileStream, "image/jpeg");


            _client.BeginRequest(twitterRequest, NewTweetCompleted);
//.........这里部分代码省略.........
开发者ID:NSemaX,项目名称:ShareToAll_WindowsPhone,代码行数:101,代码来源:PostAPhoto.xaml.cs

示例5: PostStatusesWithPic

        public void PostStatusesWithPic(String text, String path, CompleteHandler handler)
        {
            if (m_netEngine == null)
                m_netEngine = new DoubanNetEngine();
            RestRequest request = new RestRequest();
            request.Method = WebMethod.Post;
            request.Path = "shuo/v2/statuses/";
            request.AddParameter("text", text);
            request.AddParameter("source", DoubanSdkData.AppKey);

            //path = "";
            if (!String.IsNullOrEmpty(path))
            {
                IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
                if (!file.FileExists(path))
                {
                    file.Dispose();
                    DoubanEventArgs args = new DoubanEventArgs();
                    args.errorCode = DoubanSdkErrCode.XPARAM_ERR;
                    handler(args);
                    return;
                }
                file.Dispose();
                string picType = System.IO.Path.GetExtension(path);
                string picName = System.IO.Path.GetFileName(path);
                if ("png" == picType)
                {
                    request.AddFile("image", picName, path, "image/png");
                }
                else
                {
                    request.AddFile("image", picName, path, "image/jpeg");
                }
            }

            m_netEngine.SendRequest(request, (DoubanSdkResponse response) =>
            {
                if (response.errCode == DoubanSdkErrCode.SUCCESS)
                {
                    DoubanEventArgs args = new DoubanEventArgs();
                    args.errorCode = DoubanSdkErrCode.SUCCESS;
                    args.specificCode = response.specificCode;
                    handler(args);
                }
                else
                {
                    DoubanEventArgs args = new DoubanEventArgs();
                    args.errorCode = response.errCode;
                    args.specificCode = response.specificCode;
                    handler(args);
                }
            });
        }
开发者ID:thankcreate,项目名称:Care,代码行数:53,代码来源:ShuoAPI.cs

示例6: PostTweet

        void PostTweet()
        {
            var credentials = new OAuthCredentials
            {
                Type = OAuthType.ProtectedResource,
                SignatureMethod = OAuthSignatureMethod.HmacSha1,
                ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                ConsumerKey = ConsumerKey,
                ConsumerSecret = ConsumerSecret,
                Token = token,
                TokenSecret = tokenSecret,
                Version = "1.0a"
            };

            RestClient restClient = new RestClient
            {
                Authority = "https://upload.twitter.com",
                //HasElevatedPermissions = true,
                Credentials = credentials,
                Method = Hammock.Web.WebMethod.Post
            };
            RestRequest restRequest = new RestRequest
            {
                Path = "1/statuses/update_with_media.json"
            };

            restRequest.AddParameter("status", message);
            restRequest.AddFile("media[]", (new FileInfo(filePath)).Name, filePath, "image/png");

            restClient.BeginRequest(restRequest, new RestCallback(PostTweetRequestCallback));
        }
开发者ID:ummterry,项目名称:Clipoff,代码行数:31,代码来源:TwitterUtility.cs

示例7: share_Click

        private void share_Click(object sender, RoutedEventArgs e)
        {
            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                MessageBox.Show("This application must require for internet connection. Please check your internet connection status", "Sorry", MessageBoxButton.OK);
                return;
            }
            if (twitter_chk.IsChecked == false && facebook_chk.IsChecked == false && me2day_chk.IsChecked == false)
            {
                MessageBox.Show("Any account hasn't availiable. Please setting your account.", "Sorry", MessageBoxButton.OK);
                return;
            }
            else
            {
                IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
                if (WatermarkTB.Text.Length == 0 || WatermarkTB.Text == emptystr)
                {
                    MessageBox.Show("Please input your minds :)", "Sorry", MessageBoxButton.OK);
                    return;
                }
                share_status = true;
                wait_text.Text = "Share in progress.. Pleas wait";
                share_pg.Visibility = Visibility.Visible;
                tw_chk = false;
                mw_chk = false;
                fw_chk = false;
                share.Visibility = Visibility.Collapsed;

                if (me2day_chk.IsChecked == true)
                {
                    string auth_key = String.Format("full_auth_token {0}", settings["me2day_token"]);
                    IWebCredentials credentials = new BasicAuthCredentials
                    {
                        Username = (string)settings["me2day_userid"],
                        Password = auth_key
                    };

                    RestClient client = new RestClient
                    {
                        Authority = "http://me2day.net/api/"
                    };

                    RestRequest request = new RestRequest
                    {
                        Credentials = credentials,
                        Path = String.Format("create_post/{0}.xml?akey=aed420d038f9b1a7fe3b5c0d94df22f5", settings["me2day_userid"])
                    };
                    request.AddParameter("post[body]", WatermarkTB.Text);

                    if (img_bool)
                    {
                        IsolatedStorageFileStream fileStream2 = myIsolatedStorage.OpenFile("img.jpg", FileMode.Open, FileAccess.Read);
                        request.AddFile("attachment", "image.jpg", fileStream2, "image/jpeg");
                    }

                    var callback = new RestCallback(
                        (restRequest, restResponse, userState) =>
                        {
                            Dispatcher.BeginInvoke(delegate()
                            {
                                mw_chk = true;
                                chk_share();
                            });
                        }
                    );

                    client.BeginRequest(request, callback);

                }

                if (twitter_chk.IsChecked == true)
                {
                    TwitterService service = new TwitterService("g8F2KdKH40gGp9BXemw13Q", "OyFRFsI05agcJtURtLv8lpYbYRwZAIL5gr5xQNPW0Q");
                    service.AuthenticateWith((string)settings["twitter_token"], (string)settings["twitter_tokensecret"]);
                    string tweet = WatermarkTB.Text;
                    if (img_bool == true)
                        tweet += " " + twit_pic;

                    service.SendTweet(tweet,
                        (tweets, response) =>
                        {
                            Dispatcher.BeginInvoke(delegate()
                            {
                                tw_chk = true;
                                chk_share();
                            });
                        });

                }

                if (facebook_chk.IsChecked == true)
                {
                    RestClient client2 = new RestClient
                    {
                        Authority = "https://graph.facebook.com/",
                    };

                    RestRequest request2 = new RestRequest
                    {
                        Path = "/me/feed?message=" + WatermarkTB.Text
//.........这里部分代码省略.........
开发者ID:vapps,项目名称:HDStream,代码行数:101,代码来源:MainMenu.xaml.cs

示例8: photoChooserTask_Completed

        private void photoChooserTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                img_bool = true;

                using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (myIsolatedStorage.FileExists("img.jpg"))
                    {
                        myIsolatedStorage.DeleteFile("img.jpg");
                    }
                    IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile("img.jpg");
                    Uri uri = new Uri("img.jpg", UriKind.Relative);
                    BitmapImage bitmap = new BitmapImage();
                    bitmap.SetSource(e.ChosenPhoto);
                    WriteableBitmap wb = new WriteableBitmap(bitmap);
                    System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
                    wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
                    fileStream.Close();

                    photo.Content = "Remove a picture";
                    if (twitter_chk.IsChecked == true)
                    {
                        share_pg.Visibility = Visibility.Visible;
                        share.Visibility = Visibility.Collapsed;
                        var client = new RestClient
                        {
                            Authority = "http://api.twipl.net/",
                            VersionPath = "1",
                        };

                        var request = new RestRequest
                        {
                            Path = "upload.json" // can be upload.xml or whatever, but you have to parse it accordingly
                        };

                        IsolatedStorageFileStream fileStream2 = myIsolatedStorage.OpenFile("img.jpg", FileMode.Open, FileAccess.Read);
                        request.AddFile("media1", "img.jpg", fileStream2);
                        request.AddField("key", "b76ecda29f7c47e0bfefd0b458e91fb5");
                        request.AddField("oauth_token", (string)settings["twitter_token"]);
                        request.AddField("oauth_secret", (string)settings["twitter_tokensecret"]);
                        request.AddField("message", "");
                        client.BeginRequest(request, new RestCallback(Callback));
                    }
                }
            }
        }
开发者ID:vapps,项目名称:HDStream,代码行数:48,代码来源:MainMenu.xaml.cs

示例9: UploadPhoto

        private void UploadPhoto(string imagePath, string imageName, string message)
        {
            var credentials = new OAuthCredentials
                              	{
                              		Type = OAuthType.ProtectedResource,
                              		SignatureMethod = OAuthSignatureMethod.HmacSha1,
                              		ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                              		ConsumerKey = _twitterClientInfo.ConsumerKey,
                              		ConsumerSecret = _twitterClientInfo.ConsumerSecret,
                              		Token = _accessToken.Token,
                              		TokenSecret = _accessToken.TokenSecret,
                              		Version = "1.0a"
                              	};

            RestClient restClient = new RestClient
                                        {
                                            Authority = "https://upload.twitter.com",
                                            //HasElevatedPermissions = true,
                                            Credentials = credentials,
                                            Method = WebMethod.Post
                                        };
            RestRequest restRequest = new RestRequest
                                      	{
                                      		Path = "1/statuses/update_with_media.json"
                                      	};

            restRequest.AddParameter("status", message);
            restRequest.AddFile("media[]", imageName, imagePath, "image/jpg");

            restClient.BeginRequest(restRequest, PostTweetRequestCallback);
        }
开发者ID:OurDemoGroup,项目名称:Samples,代码行数:31,代码来源:MainWindow.xaml.cs

示例10: BeginRequest

        public void BeginRequest(string path, IDictionary<string, string> parameters, IDictionary<string, File> files, WebMethod method, RestCallback callback, object userState)
        {
            var request = new RestRequest
            {
                Path = path,
                Method = method
            };

            if (files != null)
            {
                foreach (var f in files)
                    request.AddFile(f.Key, f.Value.FileName, f.Value.FilePath);
            }

            if (Credentials != null)
                request.Credentials = Credentials;

            if (parameters != null)
                foreach (var p in parameters)
                {
                    request.AddParameter(p.Key, p.Value);
                }
#if !SILVERLIGHT

            if (files != null)
                foreach (var f in files)
                {
                    byte[] rawData = System.IO.File.ReadAllBytes(f.Value.FilePath);
                    request.AddPostContent(rawData);
                }
            //request.AddFile(f.Key, f.Value.FileName, f.Value.FilePath, "image/jpeg");
#endif

            Client.BeginRequest(request, (req, res, obj) =>
            {
                if (callback != null)
                    callback(req, res, obj);
            }, userState);
        }
开发者ID:bygreencn,项目名称:MahApps.RestBase,代码行数:39,代码来源:RestClientBase.cs


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