简体   繁体   English

将文件添加到 Restsharp Post 请求

[英]Adding a file to a Restsharp Post request

I am trying to attach a file to this RestSharp post request but the AddFile method errors out because it can't find the file which is in the root directory.我正在尝试将文件附加到此RestSharp发布请求,但AddFile方法出错,因为它找不到根目录中的文件。 Am I using it incorrectly?我使用不正确吗?

var client = new RestClient(ENDPOINT);
var request = new RestRequest(Method.POST);

...adding authorization to request

string path = @"C:\";
request.AddFile("file.json", path);
IRestResponse response = client.Execute(request);
string result = response.StatusDescription;

First Parameter of AddFile is not basically the name of the file but it represents the name of the parameter to be used for the request AddFile 的第一个参数基本上不是文件的名称,而是表示要用于请求的参数的名称

Official description for AddFile name parameter is The Parameter name to use in the request AddFile name 参数的官方描述是请求中使用的参数名称

string path = @"C:\file.json";
request.AddFile("nameoftheParamter", path);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM