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);
        }
示例#2
2
        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;
                }
            }
        }
示例#3
1
		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);
		}
示例#4
0
 /// <summary>
 /// Add bytes to the Files collection as if it was a file of specific type
 /// </summary>
 /// <param name="key">A form parameter name</param>
 /// <param name="filename">The file name to use for the uploaded file</param>
 /// <param name="content">The file data</param>
 /// <param name="contentType">Specific content type. Es: application/x-gzip</param>
 /// <returns>this HttpProvider</returns>
 public HttpProvider WithFile(string key, string filename, byte[] content, string contentType)
 {
     _request.AddFileBytes(key, content, filename, contentType);
     return(this);
 }
示例#5
0
文件: Form1.cs 项目: exelix11/Amiigo
 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);
 }