【问题标题】:Postman to C#(Restsharp) code snippet issuePostman 到 C#(Restsharp) 代码片段问题
【发布时间】:2018-09-12 02:31:45
【问题描述】:

我现在感觉很愚蠢,我无法弄清楚这一点。我正在使用邮递员生成一些 C#(Rest sharp) 以将文件发布到 restAPI。

在邮递员的工作文件中,它为 C# 生成的代码 sn-p 不起作用。响应代码显示 C# 中的内部服务器错误。我不知道问题出在哪里。

这里是代码 sn-p。

client = new RestClient("https://login.mydgsi.ca/WebAPI/Attachment?aboutType=Candidate&referenceID=1314180%20&attachmentTypeID=Resume&Name=Resume&expirationDate=1900/01/01&Note=Candidate%20REeume");

request = new RestRequest(Method.POST);

request.AddHeader("Postman-Token", "b339e68d-9257-44eb-8698-1f3f0c86ebfe");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Authorization", "Bearer " + secruityToken.access_token);
request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");

request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"\"; filename=\"C:\\Users\\jbungay\\Documents\\MyJabberFiles\\ddemchuk@domain.not.set\\3vertical Number 1 Resume.docx\"\r\nContent-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);

IRestResponse response = client.Execute(request);

这是邮递员帖子上的提琴手表演。我是 Fiddler 和 Postman 的新手。

Screen of the inspector from Fidder

【问题讨论】:

  • 检查 C# 代码和 Postman 请求之间的 fiddler 跟踪差异。如前所述,您收到内部服务器错误,因此它似乎是请求正文。
  • 如果您需要进一步的帮助,您可能需要分享错误消息的详细信息。
  • 在 Visual Studio 调试器中它应该 ("StatusCode: InternalServerError, Content-Type: text/plain; charset=utf-8, Content-Length: 122)
  • 比较 Postman 和您的代码发出的调用。

标签: c# postman restsharp


【解决方案1】:

尝试将“Postman-Token”更改为“token”。这在另一个项目上对我有用。请记住,请求参数会随着每个请求而变化。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-22
    • 2021-08-20
    • 2016-10-15
    • 2020-11-06
    • 2018-02-18
    • 2012-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多