本文整理汇总了C#中RestRequest.AddFile方法的典型用法代码示例。如果您正苦于以下问题:C# RestRequest.AddFile方法的具体用法?C# RestRequest.AddFile怎么用?C# RestRequest.AddFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestRequest
的用法示例。
在下文中一共展示了RestRequest.AddFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MultipartFormData_WithParameterAndFile_Async
public void MultipartFormData_WithParameterAndFile_Async()
{
const string baseUrl = "http://localhost:8888/";
using (SimpleServer.Create(baseUrl, EchoHandler))
{
RestClient client = new RestClient(baseUrl);
RestRequest request = new RestRequest("/", Method.POST)
{
AlwaysMultipartFormData = true
};
DirectoryInfo directoryInfo = Directory.GetParent(Directory.GetCurrentDirectory())
.Parent;
if (directoryInfo != null)
{
string path = Path.Combine(directoryInfo.FullName,
"Assets\\TestFile.txt");
request.AddFile("fileName", path);
}
request.AddParameter("controlName", "test", "application/json", ParameterType.RequestBody);
Task task = client.ExecuteTaskAsync(request)
.ContinueWith(x =>
{
Assert.AreEqual(this.expectedFileAndBodyRequestContent, x.Result.Content);
});
task.Wait();
}
}
示例2: MultipartFormData_WithParameterAndFile
public void MultipartFormData_WithParameterAndFile()
{
const string baseUrl = "http://localhost:8888/";
using (SimpleServer.Create(baseUrl, EchoHandler))
{
var client = new RestClient(baseUrl);
var request = new RestRequest("/", Method.POST) { AlwaysMultipartFormData = true };
string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "Assets\\TestFile.txt");
request.AddFile("fileName", path);
request.AddParameter("controlName", "test", "application/json", ParameterType.RequestBody);
var response = client.Execute(request);
Assert.AreEqual(this.expectedFileAndBodyRequestContent, response.Content);
}
}