c# - 用restsharp上传文件不会上传文件
问题描述
我在这里有一些 api 完整指南的 30 天免费试用帐户(第 24 页)(我们称之为“服务器”)。我正在尝试使用来自 NuGet dll 的 RestSharp上传文件。
问题是我总是从服务器得到文件哈希的响应,"md5": "d41d8cd98f00b204e9800998ecf8427e"
这意味着服务器收到了一个空字符串。我知道问题出在我的代码中,因为我成功通过邮递员上传。
这是我的代码:
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."
}
}
}
}
解决方案
推荐阅读
- c - AZURE 云集成
- python - 条形图上的matplotlib datetime x轴重叠问题
- c++ - 输出将如何显示?
- c++ - 如何在类 inputFactory 中调用字符串解析函数
- android - 如何使用 Hilt 创建生命周期感知组件?
- sql - Azure Devops 数据仓库部署错误 SQL72031:此部署在执行过程中可能会遇到错误
- javascript - 如何从 HTML UI 发送自适应卡片(使用 store.dispatch):microsoft/BotFramework-WebChat
- mysql - 最好将单个表用于当前和存档记录,还是一个用于存档,一个用于当前?
- java - 如何检查“在后台运行时显示弹出窗口”权限?
- javascript - CanvasJS Chart.js - 如何使axisY具有恒定范围?