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);
}
}
网友评论