0
Microsoft documentに従ってTFS APIを使用してTFSの作業項目のフィールドを更新しようとしています。ページに記載されているサンプルコードを使用している場合、APIの「アップデート作業項目」に何か問題があります。レスポンスの戻りコードは400です。何をしても、ステータスコードは常に400です。手助け?あなたは間違ったMEDIATYPEを使用している作業項目(HTTPステータス400)の更新に関するTFS API使用時のエラー
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using Newtonsoft.Json;
public void UpdateWorkItemUpdateField()
{
string _personalAccessToken = "xxxxxxxxxxxxxx";
string _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _personalAccessToken)));
string _id = "111";
Object[] patchDocument = new Object[3];
patchDocument[0] = new { op = "test", path = "/rev", value = "1" };
patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "2" };
patchDocument[2] = new { op = "add", path = "/fields/System.History", value = "Changing priority" };
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call
var method = new HttpMethod("PATCH");
var request = new HttpRequestMessage(method, "https://accountname.visualstudio.com/_apis/wit/workitems/" + _id + "?api-version=2.2") { Content = patchValue };
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
var result = response.Content.ReadAsStringAsync().Result;
}
}
}
ご協力ありがとうございます。mediaTypeを変更すると、エラーコード400が表示されなくなります。その後、私は特定の作業項目の/fields/System.Descriptionを変更しようとしていましたが、httpステータスの戻り値は400です。エラーコードはありますか?ありがとう! – RickyXRQ
@RickyXRQ新しい問題を投稿したら、ここに新しいリンクを投稿してください。 –
https://stackoverflow.com/questions/44300710/error-when-using-tfs-api-concerning-updating-work-items-http-status-500 @ Tingting0929-MSFT – RickyXRQ