本文整理汇总了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);
}
示例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;
}
}
}
示例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);
}
示例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);
}