是否可以使用RestSharp进行asynchrone文件上传?

时间:2013-04-30 16:13:04

标签: c# file-upload asynchronous restsharp asyncfileupload

我尝试使用RestSharp异步上传文件。不幸的是我无法让它发挥作用。如果我使用client.Execute()而不是client.ExecuteAsync()它的工作原理。

为什么呢?这是一个Bug吗?这是一个缺少的功能吗?这是我的错吗?

这是我的代码:

string file = "c:\\file.zip";

var request = new RestRequest(Method.POST);
request.AddFile(Path.GetFileName(file), Path.GetFullPath(file));
// Params ...

var client = new RestClient();
client.BaseUrl = url;

// Fails with sth. like TimedOut????
client.ExecuteAsync(request, response => {});
// Works
var response = client.Execute(request);

1 个答案:

答案 0 :(得分:1)

一段时间后,我发现AddFile(字符串名称,字符串路径)和AddFile(字符串名称,字符串路径)失败,而AddFile(字符串名称,Action writer,字符串fileName)与ExecuteAsync()一起使用。

相关问题