我想向 vsts 创建发布 api 发出 POST 请求,示例:POST https://fabrikam.vsrm.visualstudio.com/MyFirstProject/_apis/release/releases?api-version=4.1-preview.6
使用以下请求正文:
{
"definitionId": 1,
"description": "Creating Sample release",
"artifacts": [
{
"alias": "Fabrikam.CI",
"instanceReference": {
"id": "2",
"name": null
}
}
],
"isDraft": false,
"reason": "none",
"manualEnvironments": null
}
任何人都可以请给我一些指示在 C# 中进行相同的编码。我现在迷路了。
亲切的问候。
Edit1:我有以下代码来获取响应,我想对它进行 POST:
class Program
{
public async void GetProjects()
{
try
{
var personalaccesstoken = "PAT";
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", "", personalaccesstoken))));
using (HttpResponseMessage response = client.GetAsync(
"https://sample.vsrm.visualstudio.com/MyFirstProject/_apis/release/releases?api-version=4.1-preview.6").Result)
//POST to response with Json body
{
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
static void Main(string[] args)
{
Program prog = new Program();
prog.GetProjects();
}
}
相关分类