【问题标题】:Restsharp addFile() can't read file path correctlyRestsharp addFile() 无法正确读取文件路径
【发布时间】:2020-02-29 19:28:53
【问题描述】:

我正在尝试在上传 3 个 .csv 文件后测试响应,作为我目前正在进行的项目 API 集成测试的一部分。

public void UploadFile(string token)
    {
        request = new RestRequest(Method.POST);
        endpoint.Timeout = -1;
        request.AlwaysMultipartFormData = true;
        request.AddHeader("Authorization", $"Bearer {token}");
        request.AddHeader("Content-Type", "multipart/form-data");
        request.AddFile("Customers", "Users/Dell/Downloads/ProRecoFiles/CUSTOMERS.csv");
        //request.AddFile(Constants.customers, Constants.customersPath);
        //request.AddFile(Constants.orders, Constants.ordersPath);
        //request.AddFile(Constants.products, Constants.productsPath);
        endpoint.Execute(request);
    }

虽然我对 Restsharp 和 C# 比较陌生,但我会说这是非常直接的请求。但显然我得到了一些错误:

Message: 
System.IO.FileNotFoundException : Could not find file 'C:\Users\Dell\Source\Repos\proreco-client-api\ProReco.Client.API\Tests\bin\Debug\netcoreapp3.1\Users\Dell\Downloads\ProRecoFiles\CUSTOMERS.csv'.

在 request.AddFile() 中,我将文件名和文件路径传递给文件。不知何故,它将文件路径的值连接到我的项目位置。知道如何解决吗?任何建议都会很棒。

【问题讨论】:

    标签: api testing file-upload integration-testing restsharp


    【解决方案1】:

    在路径前加上“C:/”。例如。: request.AddFile("Customers","C:/Users/Dell/Downloads/ProRecoFiles/CUSTOMERS.csv");

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-10
      • 2019-01-19
      • 2021-12-07
      • 1970-01-01
      • 1970-01-01
      • 2018-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多