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


C# RestRequest.AddFileBytes方法代码示例

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


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

示例1: CrudTest

        public void CrudTest()
        {
            var bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var filename = "something.dummy";
            var mimetype = "application/octet-stream";
            var restClient = new RestClient(baseFileserverUrl);
            var post = new RestRequest(Method.POST);
            post.AddFileBytes(filename, bytes, filename, mimetype);
            var postRes = restClient.Execute(post);
            LogRequest(restClient, post, postRes, 0);

            Assert.AreEqual(ResponseStatus.Completed, postRes.ResponseStatus);
            Assert.AreEqual(HttpStatusCode.Created, postRes.StatusCode);
            var location = postRes.Headers.First(e => e.Name.Equals("Location")).Value.ToString();
            Assert.IsNotNull(location);

            var uri = new Uri(location);
            var filestorageClient = new RestClient(uri);
            var get = new RestRequest(Method.GET);
            var gerRes = filestorageClient.Execute(get);
            Assert.AreEqual(ResponseStatus.Completed, gerRes.ResponseStatus);
            Assert.AreEqual(HttpStatusCode.OK, gerRes.StatusCode);
            Assert.AreEqual(10, gerRes.RawBytes.Length);
            Assert.AreEqual(mimetype, gerRes.ContentType);

            var del = new RestRequest(Method.DELETE);
            var delRes = filestorageClient.Execute(del);
            Assert.AreEqual(ResponseStatus.Completed, delRes.ResponseStatus);
            Assert.AreEqual(HttpStatusCode.NoContent, delRes.StatusCode);
        }
开发者ID:CactusSoft,项目名称:Cactus.Fileserver,代码行数:30,代码来源:CrudIntegrationTest.cs

示例2: UploadImage

        private async Task<IRestResponse> UploadImage(Bitmap curImage, string filename)
        {
            using (var memoryStream = new MemoryStream())
            {
                var codecInfo = GetEncoder(imageFormatType);
                if (codecInfo.FormatDescription == "JPEG")
                    curImage.Save(memoryStream, codecInfo, imageEncoderParameters);
                else
                    curImage.Save(memoryStream, imageFormatType);

                var restClient = new RestClient("http://daash.pw/cgi-bin/upload.pl");
                var request = new RestRequest(Method.POST);
                request.AddParameter("key", uploadKey);
                request.AddFileBytes("fileToUpload0", memoryStream.ToArray(), filename, "multipart/form-data");

                try
                {
                    return await restClient.ExecuteTaskAsync(request);
                }
                catch (Exception)
                {
                    return null;
                }
            }
        }
开发者ID:NoiseDoll,项目名称:daash,代码行数:25,代码来源:MainForm.cs

示例3: SendFile

		public Task<string> SendFile(string method, string path, string filename, Stream stream, CancellationToken cancelToken)
		{
			var request = new RestRequest(path, GetMethod(method));
			request.AddHeader("content-length", (stream.Length - stream.Position).ToString());

			byte[] bytes = new byte[stream.Length - stream.Position];
			stream.Read(bytes, 0, bytes.Length);
			request.AddFileBytes("file", bytes, filename);
			//request.AddFile("file", x => stream.CopyTo(x), filename); (Broken in latest ver)

			return Send(request, cancelToken);
		}
开发者ID:MarlboroTX,项目名称:Discord.Net,代码行数:12,代码来源:SharpRestEngine.cs

示例4: DecryptDump

 byte[] DecryptDump(byte[] encBin)
 {
     RestClient client = new RestClient("https://www.socram.ovh/amiibo/");
     RestRequest request = new RestRequest("api.php", Method.POST);
     request.AddParameter("MAX_FILE_SIZE", 540);
     request.AddParameter("operation", "decrypt");
     request.AddFileBytes("dump", encBin, @"Dump.bin");
     return client.DownloadData(request);
 }
开发者ID:exelix11,项目名称:Amiigo,代码行数:9,代码来源:Form1.cs


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