我想使用Synology Filestation API上传TXT文件,但我有错误。你能帮我吗?
我想通过 FileStation API 将 txt 文件发送到 NAS 设备,并且我正在使用 C# 进行编码。当我在 Postman 中发布请求时,请求成功并且文件已上传。但在 C# 中,我使用 RestSharp Framework 来发布请求。但在某些情况下我会收到错误 101 或 401。在下面,我发送我的代码。谢谢您的回复。
var client = new RestClient(url);
var request = new RestRequest("/webapi/entry.cgi", Method.Post);
request.AddHeader("Cookie", "did="+_did+"; id="+_sid);
request.AddParameter("api", "SYNO.FileStation.Upload", ParameterType.RequestBody);
request.AddParameter("version", "3", ParameterType.RequestBody);
request.AddParameter("method", "upload", ParameterType.RequestBody);
request.AddParameter("path", "my_path", ParameterType.RequestBody);
request.AddParameter("create_parents", "False", ParameterType.RequestBody);
request.AddFile("filename", filename, "application/octet-stream");
var response = client.ExecutePostAsync(request).Result;
I want to send txt file to NAS device via FileStation API and I am coding in C#. When I posted request in Postman, request is successful and file is uploaded. But in C#, I use RestSharp Framework to post request. But I get error 101 or 401 in some situation. In below, I send my code. Thank you for your replies.
var client = new RestClient(url);
var request = new RestRequest("/webapi/entry.cgi", Method.Post);
request.AddHeader("Cookie", "did="+_did+"; id="+_sid);
request.AddParameter("api", "SYNO.FileStation.Upload", ParameterType.RequestBody);
request.AddParameter("version", "3", ParameterType.RequestBody);
request.AddParameter("method", "upload", ParameterType.RequestBody);
request.AddParameter("path", "my_path", ParameterType.RequestBody);
request.AddParameter("create_parents", "False", ParameterType.RequestBody);
request.AddFile("filename", filename, "application/octet-stream");
var response = client.ExecutePostAsync(request).Result;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后一行代码是错误的。因为这是一个异步调用,所以你必须等待它。但是,这意味着该代码所在的方法需要标记为异步。您没有显示该代码,因此不确定这是否在 Main 方法中。但最终,它应该看起来像这样:
The last line of code is what is wrong. Because it is an Async call, you have to await it. However, that means the method this code is in needs to be marked as async. You aren't showing that code, so not sure if this is in the Main method or not. But ultimately, it should look like this:
我遇到了同样的问题,使用Java,服务器返回101。如果有解决方案,请告诉我。谢谢。
I have encountered the same problem, using Java, the server returns 101. If there is a solution, please let me know. Thank you.