通过REST API向Fortify Issue添加评论会导致内容编码错误

时间:2018-10-03 19:44:51

标签: c# .net rest fortify

我正在尝试对Fortify内部的问题添加评论。当我发布我认为正确的JSON时,我收到响应“ {“ message”:“内容格式错误(预期的application / json; charset = utf-8)。”,“ responseCode”:400,“ errorCode” :-20209}“

但是,如果我使用Fiddler来检查我正在发布的消息,并且接收到适当的标头,那么它们似乎就位。哪些次要问题可能导致引发此异常?

Fortify v18.10.0187
.NET v4.6.2
Newtonsoft.Json v9.0.0

 public static string PostCommentIssue(FortifyComment fc)
 {
      var content = JsonConvert.SerializeObject(fc);
      var postUri = String.Format(Configuration.FortifyCommentsUri, fc.data.issueId);
      return WebServiceHelper.PostMessage(postUri, content);
 }

 public static string PostMessage(string url, string content)
 {
      HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, url);
      requestMessage.Headers.Add("Authorization", Configuration.FortifyAuthorization.ToHeader());
      requestMessage.Content = new StringContent(content, Encoding.UTF8, JsonMediaTypeFormatter.DefaultMediaType.MediaType);

      HttpResponseMessage hrm = HttpClient.SendAsync(requestMessage).Result;
      hrm.EnsureSuccessStatusCode();
      HttpContent hc = hrm.Content;

      return hc.ReadAsStringAsync().Result;
 }

FortifyComment只是一个对象,其中包含注释的基本元素。它基于查询给出的Fortify响应(因此是内部数据元素)。

使用

 FortifyComment fc = new FortifyComment();
 fc.data.issueId = defect.id;
 fc.data.comment = String.Format("TFS #{0}.", tfsNumber);
 FortifyHelper.PostCommentIssue(fc);

我收到400错误。 Fiddler截屏截图: Fiddler capture 1 Fiddler capture 2 (request body)

0 个答案:

没有答案