使用restsharp上传文件不会上传文件

时间:2018-09-05 06:53:07

标签: c# api restsharp

我有30天免费试用帐户,可以使用某些api full guide here (Page 24)(我们称之为“服务器”)。我正在尝试使用RestSharp from NuGet dll上传文件。

问题是,我总是从服务器得到以下响应:文件哈希为"md5": "d41d8cd98f00b204e9800998ecf8427e",这意味着服务器接收到empty string。我知道问题出在我的代码中,因为我可以通过邮递员成功上传。

这是我的代码:

var path = @"C:\Users\daniel\Desktop\In\someFile.pdf";        
var client = new RestClient("https://te.checkpoint.com/tecloud/api/v1/file/upload");
var request = new RestRequest(Method.POST);    
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Authorization", "6610F8512D02");
request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
request.AddFile("someFile.pdf", path);   
request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"someFile.pdf\"\r\nContent-Type: text/plain\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

请分享您的知识

邮递员回复:

{
    "response": {
        "status": {
            "code": 1002,
            "label": "UPLOAD_SUCCESS",
            "message": "The file was uploaded successfully."
        },
        "md5": "d299af47bcb153189cbc7384bfae255f",
        "file_type": "",
        "file_name": "linktopdf.txt",
        "features": [
            "te"
        ],
        "te": {
            "trust": 0,
            "images": [
                {
                    "report": {
                        "verdict": "unknown"
                    },
                    "status": "not_found",
                    "id": "e50e99f3-5963-4573-af9e-e3f4750b55e2",
                    "revision": 1
                },
                {
                    "report": {
                        "verdict": "unknown"
                    },
                    "status": "not_found",
                    "id": "5e5de275-a103-4f67-b55b-47532918fa59",
                    "revision": 1
                }
            ],
            "score": -2147483648,
            "status": {
                "code": 1002,
                "label": "UPLOAD_SUCCESS",
                "message": "The file was uploaded successfully."
            }
        }


}

来自我的应用的回复:

{
  "response": {
    "status": {
      "code": 1001,
      "label": "FOUND",
      "message": "The request has been fully answered."
    },
    "md5": "d41d8cd98f00b204e9800998ecf8427e",
    "file_type": "",
    "file_name": "someFile.pdf",
    "features": [
      "te"
    ],
    "te": {
      "trust": 10,
      "images": [
        {
          "report": {
            "verdict": "benign"
          },
          "status": "found",
          "id": "e50e99f3-5963-4573-af9e-e3f4750b55e2",
          "revision": 1
        },
        {
          "report": {
            "verdict": "benign"
          },
          "status": "found",
          "id": "5e5de275-a103-4f67-b55b-47532918fa59",
          "revision": 1
        }
      ],
      "score": -2147483648,
      "combined_verdict": "benign",
      "status": {
        "code": 1001,
        "label": "FOUND",
        "message": "The request has been fully answered."
      }
    }
  }
}

0 个答案:

没有答案