我正在尝试将文件上传到某些api,我用postman做了一个小测试,this guy的视频帮助了我。它工作正常!
因此,我从邮递员那里复制了代码,可以通过单击“代码”来实现:
这是邮递员使用的C#代码:
var client = new RestClient("https://te.checkpoint.com/tecloud/api/v1/file/upload");
var request = new RestRequest(Method.POST);
request.AddHeader("Postman-Token", "616790a7-ad25-4687-a749-0b36998b04ac");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Authorization", "6610F8512D02");
request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"C:\\Users\\Plompy\\Downloads\\rr.pdf\"\r\nContent-Type: application/pdf\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
但是当我从C#控制台应用程序尝试时,我会收到响应(需要NuGet的RestSharp DLL)::
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>
我不在乎您看到我的自动复写密钥。这是一个30天的免费试用帐户。