Asp.net web api 为什么这个RestSharp文件上传不起作用?

Asp.net web api 为什么这个RestSharp文件上传不起作用?,asp.net-web-api,restsharp,asp.net-core-webapi,Asp.net Web Api,Restsharp,Asp.net Core Webapi,我有以下ASP.NET核心Web API操作方法: [HttpPost("PostDir")] [DisableRequestSizeLimit] public async Task<IActionResult> PostDir(string serverPath) { // Do stuff with file. return Ok(); } 我遗漏了什么或做错了什么?可能重复@saj-funcy,这也是我的问题。我在这里问过这个,以防它是具体的。 public

我有以下ASP.NET核心Web API操作方法:

[HttpPost("PostDir")]
[DisableRequestSizeLimit]
public async Task<IActionResult> PostDir(string serverPath)
{
    // Do stuff with file.
    return Ok();
}

我遗漏了什么或做错了什么?

可能重复@saj-funcy,这也是我的问题。我在这里问过这个,以防它是具体的。
public async Task PostDirAsync(string localDirPath, string serverDir)
{
    var sourcePath = Path.Combine("Temp", Guid.NewGuid() + ".zip");
    ZipFile.CreateFromDirectory(localDirPath, sourcePath, CompressionLevel.Fastest, true);

    var rest = new RestClient("http://localhost:50424/api/File/PostDir");
    var req = new RestRequest(Method.POST);
    req.AddFile(Path.GetFileName(sourcePath), sourcePath);
    req.AddHeader("Content-Type", "multipart/form-data");
    req.AddParameter("serverPath", serverDir, ParameterType.QueryString);

    var resp = rest.Execute(req);
}