跳到主要内容

检索 Qlik NPrinting 应用程序的列表

以下代码扩展了 .NET 控制台应用程序的之前示例,方法是创建经验证的连接并检索 Qlik NPrinting 应用程序列表。请记住将 server.name.com 替换为您的实际 Qlik NPrinting Server 名称。

信息注释该示例中的 JSON 反序列化方法使用来自 Newtonsoft 的第三方库来将 JSON 转换为对象。

static void Main(string[] args) { //Create the HTTP Request (authenticate) and add required headersServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@ "https://server.name.com:4993/api/v1/login/ntlm"); CookieContainer cookies = new CookieContainer(); request.CookieContainer = cookies; request.Method = "GET"; request.UserAgent = "Windows"; request.Accept = "application/json"; // specify to run as the current Microsoft Windows user request.UseDefaultCredentials = true; try { // make the web request and return the content HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader responseReader = new StreamReader(response.GetResponseStream()); string sResponseHTML = responseReader.ReadToEnd(); Console.WriteLine(sResponseHTML); } catch (Exception ex) { Console.WriteLine(ex.Message); } //Create second HTTP request (get list of apps) and add required headers HttpWebRequest secondRequest = (HttpWebRequest)WebRequest.Create(@ "https://server.name.com:4993/api/v1/apps"); //assign cookie to request to maintain session secondRequest.CookieContainer = cookies; secondRequest.Method = "GET"; secondRequest.UserAgent = "Windows"; secondRequest.Accept = "application/json"; // specify to run as the current Microsoft Windows user secondRequest.UseDefaultCredentials = true; try { HttpWebResponse response2 = (HttpWebResponse)secondRequest.GetResponse(); StreamReader responseReader2 = new StreamReader(response2.GetResponseStream()); string sResponseHTML2 = responseReader2.ReadToEnd(); dynamic jsonObj = JsonConvert.DeserializeObject(sResponseHTML2); foreach (var app in jsonObj.data.items) { Console.WriteLine(app.name); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.Read(); }

本页面有帮助吗?

如果您发现此页面或其内容有任何问题 – 打字错误、遗漏步骤或技术错误 – 请告诉我们如何改进!