通过 Wiql (WorkItem) 查询给出错误请求状态
Posted
技术标签:
【中文标题】通过 Wiql (WorkItem) 查询给出错误请求状态【英文标题】:Query By Wiql (WorkItem) Give Bad Request Status 【发布时间】:2019-09-13 14:41:38 【问题描述】:我正在尝试为工作项调用 post API(DevOps),但它显示状态“错误请求”。
如果我调用一些 GET API(DevOps),它工作正常。我按照以下链接调用 POST API:
https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/wiql/query%20by%20wiql?view=azure-devops-rest-5.0
代码:
using (var client = new HttpClient())
string content = "'query': 'Select [System.Id], [System.Title], [System.State] From WorkItems'";
client.BaseAddress = new Uri("http://YYYYY.com:8080/tfs/YY"); //url of your organization
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);
var response = client.PostAsJsonAsync(new Uri("http://YYYYY.com:8080/tfs/YY/_apis/wit/wiql?api-version=1.0"), content).Result;
if (response.IsSuccessStatusCode)
Console.Write("Success");
else
Console.Write("Error");
【问题讨论】:
如果您使用的是本地 TFS(根据您查询的 URI,您似乎在使用它),什么版本? 【参考方案1】:你可以试试下面的代码:
var personalaccesstoken = "xxxxxxxxxx";
var base64Token = Convert.ToBase64String(Encoding.ASCII.GetBytes($":personalaccesstoken"));
using (HttpClient client = new HttpClient())
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64Token);
var requestMessage = new HttpRequestMessage(HttpMethod.Post, "http://tfsserver:8080/tfs/DefaultCollection/_apis/wit/wiql?api-version=1.0");
requestMessage.Content = new StringContent("\"query\": \"select [System.Id], [System.Title], [System.State] from WorkItems\"", Encoding.UTF8, "application/json");
using (HttpResponseMessage response = client.SendAsync(requestMessage).Result)
response.EnsureSuccessStatusCode();
【讨论】:
以上是关于通过 Wiql (WorkItem) 查询给出错误请求状态的主要内容,如果未能解决你的问题,请参考以下文章
为啥我的 WorkItem 由于未处理的访问冲突错误而失败?
Flutter 通过查询 Firestore 创建自定义用户模型给出“类型‘Future<dynamic>’不是‘String’类型的子类型”错误