restsharp postman code multipart post 请求将 0kb 图像发送到 JIRA
restsharp postman code multipart post request sending 0kb images to JIRA
我正在处理 post 通过它们的其余部分将图像发送到 JIRA 票证 API(需要具有自定义 headers 的多部分 post)。
在 postman 中一切正常,它生成的 restsharp 代码如下:
var client = new RestClient("jira link here");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Connection", "keep-alive");
request.AddHeader("Content-Length", "31321");
request.AddHeader("Cookie", "atlassian.xsrf.token=BMR0-T49H-M7PK-ZG4J_4f2a8b5df5dfd91780d88b5ea26f8de0_lin; JSESSIONID=CE20BD6E7D3FABA7A0E8F9403907CD97");
request.AddHeader("Accept-Encoding", "gzip, deflate");
request.AddHeader("Host", "classified");
request.AddHeader("Postman-Token", "b5f2a773-532a-47b7-83bd-36c3cce16b55,d07661e4-abf5-408e-be59-0360938b6b77");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Accept", "*/*");
request.AddHeader("User-Agent", "PostmanRuntime/7.18.0");
request.AddHeader("Authorization", "classified");
request.AddHeader("X-Atlassian-Token", "no-check");
request.AddHeader("Content-Type", "multipart/form-data");
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=\"1280px-Microsoft_Azure_Logo.svg - Copy.png\"\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
我怀疑问题可能是没有图像的完整路径,尝试添加路径,现在正在 posting 图像,但图像是空白的,0kb。当 posted 到 JIRA 时图像名称是正确的。
图像似乎是正确的,但名称正确是空白。
我也试过包括 request.addFile("x",@path);
还是不行。
这是服务器的响应:
enter image description here
事实证明,postman 在其自动生成的代码中添加了一堆额外的东西,无论如何 postman 上的代码生成需要修复,这是我修复我的代码的方法:
RestClient restClient = new RestClient("link here");
RestRequest restRequest = new RestRequest("/attachments");
restRequest.RequestFormat = DataFormat.Json;
restRequest.Method = Method.POST;
restRequest.AddHeader("Content-Length", int.MaxValue.ToString());
restRequest.AddHeader("Authorization", "secret");
restRequest.AddHeader("X-Atlassian-Token", "no-check");
restRequest.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
restRequest.AddHeader("Content-Type", "multipart/form-data");
restRequest.AddFile("file", path);
var response = restClient.Execute(restRequest);
我正在处理 post 通过它们的其余部分将图像发送到 JIRA 票证 API(需要具有自定义 headers 的多部分 post)。 在 postman 中一切正常,它生成的 restsharp 代码如下:
var client = new RestClient("jira link here");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Connection", "keep-alive");
request.AddHeader("Content-Length", "31321");
request.AddHeader("Cookie", "atlassian.xsrf.token=BMR0-T49H-M7PK-ZG4J_4f2a8b5df5dfd91780d88b5ea26f8de0_lin; JSESSIONID=CE20BD6E7D3FABA7A0E8F9403907CD97");
request.AddHeader("Accept-Encoding", "gzip, deflate");
request.AddHeader("Host", "classified");
request.AddHeader("Postman-Token", "b5f2a773-532a-47b7-83bd-36c3cce16b55,d07661e4-abf5-408e-be59-0360938b6b77");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Accept", "*/*");
request.AddHeader("User-Agent", "PostmanRuntime/7.18.0");
request.AddHeader("Authorization", "classified");
request.AddHeader("X-Atlassian-Token", "no-check");
request.AddHeader("Content-Type", "multipart/form-data");
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=\"1280px-Microsoft_Azure_Logo.svg - Copy.png\"\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
我怀疑问题可能是没有图像的完整路径,尝试添加路径,现在正在 posting 图像,但图像是空白的,0kb。当 posted 到 JIRA 时图像名称是正确的。
图像似乎是正确的,但名称正确是空白。
我也试过包括 request.addFile("x",@path); 还是不行。
这是服务器的响应: enter image description here
事实证明,postman 在其自动生成的代码中添加了一堆额外的东西,无论如何 postman 上的代码生成需要修复,这是我修复我的代码的方法:
RestClient restClient = new RestClient("link here");
RestRequest restRequest = new RestRequest("/attachments");
restRequest.RequestFormat = DataFormat.Json;
restRequest.Method = Method.POST;
restRequest.AddHeader("Content-Length", int.MaxValue.ToString());
restRequest.AddHeader("Authorization", "secret");
restRequest.AddHeader("X-Atlassian-Token", "no-check");
restRequest.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
restRequest.AddHeader("Content-Type", "multipart/form-data");
restRequest.AddFile("file", path);
var response = restClient.Execute(restRequest);