使用有关更新工作项的 TFS API 时出错(HTTP 状态 500) [英] Error when using TFS API concerning updating work items( HTTP Status 500 )

查看:30
本文介绍了使用有关更新工作项的 TFS API 时出错(HTTP 状态 500)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据 Microsoft 官方文档使用 TFS API 更新 TFS 上工作项的字段 (/fields/System.Description).使用页面上列出的示例代码时,api更新工作项"有问题,如果我想添加"或替换"某个字段,则响应的返回状态代码为 500,但如果我成功想测试"一个值,谁能给我一些帮助?

I am trying to update a field(/fields/System.Description) of a work-item on TFS using the TFS API according to the official Microsoft document. There is something wrong with the api "Update work items" when using the sample code listed on the page, the returning status code of the response is 500 if I want to "add" or "replace" a certain filed, but success if I want to "test" a value, can anyone please give me some help?

using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;

using Newtonsoft.Json;

public static void UpdateWorkItemUpdateField()
    {
        string _personalAccessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
        string _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _personalAccessToken)));
        string _id = "111";

        Object[] patchDocument = new Object[1];

        patchDocument[0] = new { op = "replace", path = "/fields/System.Description", value = "Changing the description done" };


        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-patch+json"); // mediaType needs to be application/json-patch+json for a patch call
            var method = new HttpMethod("PATCH");
            var request = new HttpRequestMessage(method, "http://mysite:8080/tfs/MyCollection/_apis/wit/workitems/" + _id + "?api-version=1.0") { Content = patchValue };
            var response = client.SendAsync(request).Result;

            if (response.IsSuccessStatusCode)
            {
                var result = response.Content.ReadAsStringAsync().Result;
            }
        }
    }

这里是返回状态:

{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1,内容:System.Net.Http.StreamContent,标题:{ Pragma: no-cacheX-TFS-ProcessId: xxxxxxxxxxxxxxxx X-FRAME-OPTIONS: SAMEORIGINX-VSS-UserData: xxxxxxxxxxxxxxxxxxxxxxxxxx:xxxxx ActivityId:xxxxxxxxxxxxxxxxxxxxxxxxxxxx X-TFS-Session: xxxxxxxxxxxxxxxxxLfs-Authenticate: NTLM X-Content-Type-Options: nosniff缓存控制:无缓存日期:2017 年 6 月 1 日星期四 06:50:04 GMT P3P:CP="CAO DSP COR ADMa DEV CONo TELo CUR PSA PSD TAI IVDo 我们的SAMi BUSDEM NAV STA UNI COM INT PHY ONL FIN PUR LOC CNT" 服务器:Microsoft-IIS/7.5 X-AspNet-版本:4.0.30319 X-Powered-By:ASP.NET内容长度:428 内容类型:应用程序/json;字符集=utf-8过期时间:-1}}

{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:{ Pragma: no-cache X-TFS-ProcessId: xxxxxxxxxxxxxxxx X-FRAME-OPTIONS: SAMEORIGIN X-VSS-UserData: xxxxxxxxxxxxxxxxxxxxxxxxxx:xxxxx ActivityId: xxxxxxxxxxxxxxxxxxxxxxxxxxxx X-TFS-Session: xxxxxxxxxxxxxxxxx Lfs-Authenticate: NTLM X-Content-Type-Options: nosniff Cache-Control: no-cache Date: Thu, 01 Jun 2017 06:50:04 GMT P3P: CP="CAO DSP COR ADMa DEV CONo TELo CUR PSA PSD TAI IVDo OUR SAMi BUS DEM NAV STA UNI COM INT PHY ONL FIN PUR LOC CNT" Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Content-Length: 428 Content-Type: application/json; charset=utf-8 Expires: -1}}

推荐答案

我尝试提出相同的请求,但只是在 url 中没有 MyCollection 部分,并且成功了.

I tried to make the same request but only without the MyCollection part in the url and it worked.

尝试自己做.丹尼

这篇关于使用有关更新工作项的 TFS API 时出错(HTTP 状态 500)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆