我正在使用 REST API 使用 REST API文档创建工作项。为此,我需要使用 Patch 请求,但此代码不起作用。程序以代码 0 (0x0) 退出。
HttpClientHandler httpClientHandler = new HttpClientHandler();
using (HttpClient client = new HttpClient(httpClientHandler))
{
var content = "[{'op': 'add','path': '/fields/System.Title', 'value': 'Title' }]";
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
string URLTest = "https://MyProject.visualstudio.com/DefaultCollection/ProjectName/_apis/wit/workitems/$Task?api-version=2.0";
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", "*******", "******"))));
var method = new HttpMethod("PATCH");
var request = new HttpRequestMessage(method, URLTest)
{
Content = new StringContent(content, Encoding.UTF8,
"application/json-patch+json")
};
HttpResponseMessage response = await client.SendAsync(request);