gpt4 book ai didi

azure - RestSharp PATCH API 调用更新 Azure Devops 工作项抛出 BAD 请求 - "You must pass a valid patch document in the body of the request."

转载 作者:行者123 更新时间:2023-12-03 07:04:06 42 4
gpt4 key购买 nike

我正在使用 RestSharp v107。

我想更新测试用例的迭代路径。我可以使用 Postman 更新它,但使用 RestSharp 我收到“BAD Request”-“您必须在请求正文中传递有效的补丁文档。”

Azure Devops Update Work Item Rest API

我的代码:

        var client = new RestClient(@"https://dev.azure.com/krakhil/AkhilProject/_apis/wit/workitems/25?api-version=6.1-preview.3&Authorization=Basic BASE64PATSTRING");
client.Authenticator = new HttpBasicAuthenticator("", "My_PAT_I_HAVE_GENERATED");

var request = new RestRequest();
request.AddHeader("Content-Type", "application / json - patch + json");

var body = @"[
" + "\n" +
@" {
" + "\n" +
@" ""op"": ""add"",
" + "\n" +
@" ""path"": ""/fields/System.IterationPath"",
" + "\n" +
@" ""value"": ""AkhilProject\\Sprint 1""
" + "\n" +
@" }
" + "\n" +
@"]";

request.AddParameter("application/json-patch+json", body, ParameterType.RequestBody);

var response = client.PatchAsync(request).Result;

我尝试过“AddJSONBody”、ExecuteAsync - 进行了相应的更改。仍然没有帮助。

最佳答案

有时阅读文档会有所帮助。

您需要做的就是:

var request = new RestRequest()
.AddStringBody(body, "application/json-patch+json");

关于azure - RestSharp PATCH API 调用更新 Azure Devops 工作项抛出 BAD 请求 - "You must pass a valid patch document in the body of the request.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71747362/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com