我正在尝试使用 REST API version=5.1-preview.3向工作项发布讨论评论。
概括
类型:POST 和 C# HttpClient
然而,无论我如何尝试使用它,我总是得到回应:
StatusCode: 415, ReasonPhrase: 'Unsupported Media Type'
内心的反应是这样的:
{"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred. Activity Id: d634683c-0b2e-4bfb-9a66-ee99f32404c6.","typeName":"System.Web.Http.HttpResponseException, System.Web.Http","typeKey":"HttpResponseException..
我以以下 JSON 格式发送数据/评论:
[
{
"text": "Test Comment"
}
]
如文档中所述:
要求
我正在尝试使用 API:
使用以下示例代码:
public class Comment
{
[JsonProperty("text")]
public string Text { get; set; }
}
var comment = new Comment()
{
Text = "Test Comment"
};
var comments = new List<Comment>();
comments.Add(comment);
var body = JsonConvert.SerializeObject(comments);
var postValue = new StringContent(body, Encoding.UTF8, "application/json-patch+json");
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _token))));
using (HttpRequestMessage httpRequestMessage = new HttpRequestMessage(new HttpMethod("POST"), _apiUrl) { Content = postValue })
{
var httpResponseMessage = httpClient.SendAsync(httpRequestMessage).Result;
}
}
我相信上面的代码片段应该能够为工作项添加评论。然而,无论我如何尝试使用它,我总是得到回应:
回复
StatusCode: 415, ReasonPhrase: 'Unsupported Media Type'
内心的反应是这样的:
{"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred. Activity Id: d634683c-0b2e-4bfb-9a66-ee99f32404c6.","typeName":"System.Web.Http.HttpResponseException, System.Web.Http","typeKey":"HttpResponseException..
你能帮帮我吗?
提前致谢!