好的,这是自从我将RestSharp更新为当前版本以来的C#代码:
restRequest.Files.Add((FileParameter)file); // Added cast for clarity
根据,这是正确的选择:
restRequest.AddFile((FileParameter)file);
但是,这似乎是不正确的,因为它引发了此例外:
方法“ addfile”没有超载
这是1个参数直接与RestSharp文档相矛盾。我找不到任何方法来解决这个问题。我尝试了那里的过载,但是FileParameter不再包含所需的作家属性,我找不到任何文档提及移至何处的文档。
我想念什么?
Ok so here's the C# code that's breaking since I updated RestSharp to the current version:
restRequest.Files.Add((FileParameter)file); // Added cast for clarity
According to the the current official documentation, this is the correct alternative:
restRequest.AddFile((FileParameter)file);
However, that appears to be incorrect, as it throws this exception:
No overload for method 'AddFile' takes 1 arguments
This directly contradicts the RestSharp docs. I haven't been able to find any way to get around this. I tried the overloads that are there but FileParameter no longer contains the Writer property which would be required and I can't find any docs mentioning where that was moved to.
What am I missing?
发布评论
评论(3)
restrequest.files
是 READONLY集合因此,您无法使用该属性添加更多文件。由于Overload
Restrequest.addfile(((fileparameter)文件);
在较新版本的RestSharp中不存在,因此您可以定义自己的扩展方法:另一种方法:另一种方法:
restRequest.Files
is readonly collection so you cannot use that property to add more files.Since the overload
restRequest.AddFile((FileParameter)file);
is not there in the newer version of restsharp, you can define your own extension method like this:Another way:
我也遇到了这个问题(RestSharp 108.0.1),同时使用API集成。我能够通过将文件添加到请求正文中来解决问题。
I just came across this issue as well (restsharp 108.0.1) while working with an api integration. I was able to get around the issue by adding my file into the request body.
addfile(fileparameter)
已被标记为@serg注释的内部
,因此request> request.addfile(fileparameter);
将在以后无法使用版本除非他们再次删除内部
修饰符。至于
Action< stream> writer
fileparameter的属性
,现在变成func< stream> getfile
。要指定您自己的getfile
,您可以使用指定的getfile
来调用内部addfile(fileparameter)
来调用此方法
扩展 有点混淆旧版本是
action< stream>
库将stream
将传递给您的writer
,现在您需要传递<<<代码>流通过getfile
到库。The
AddFile(FileParameter)
has been marked asinternal
as commented by @Serg, sorequest.AddFile(fileParameter);
will not work in later version unless they remove theinternal
modifier again.As to the
Action<Stream> Writer
property ofFileParameter
, now it becomesFunc<Stream> GetFile
. To specify your ownGetFile
, you could call this extension methodwhich will call the
internal AddFile(FileParameter)
using the specifiedGetFile
:It would be a bit confusing that old versions is
Action<Stream>
where the library will pass theStream
to yourWriter
and now you need to pass theStream
to the library viaGetFile
.