美文网首页
C# HttpClient 与Jenkins Rest API

C# HttpClient 与Jenkins Rest API

作者: Beyfound | 来源:发表于2020-06-10 22:58 被阅读0次

    c#

    使用HttpClient

    public static async void GetContent()
            {
                using (var client = new HttpClient())
                {
                    var userName = "adm";
                    var passwd = "11c2d2167ff4c9e1710a6ff86d344e2c9c";
                    var url = "http://localhost:8080/job/JenkinsTest/lastBuild/api/json";
    
    
                    var authToken = Encoding.ASCII.GetBytes($"{userName}:{passwd}");
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                            Convert.ToBase64String(authToken));
                    var result = await client.GetStringAsync(url);
                    JObject jo = (JObject)JsonConvert.DeserializeObject(result);
                    string zone = jo["building"].ToString();
                    while (bool.Parse(zone))
                    {
                        Thread.Sleep(2000);
                        result = await client.GetStringAsync(url);
                        jo = (JObject)JsonConvert.DeserializeObject(result);
                        zone = jo["building"].ToString();
                    }
                    Console.WriteLine(result);
                }
            }
    

    相关文章

      网友评论

          本文标题:C# HttpClient 与Jenkins Rest API

          本文链接:https://www.haomeiwen.com/subject/lnfmtktx.html