Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

Announcements
Qlik® Product Spotlight: Discover what’s possible. Get more from our products.
See for yourself. Register today.
Not applicable

Qlik Engine html response (C#)

Hello,

I have some trouble to make a Qlik Engine call (qlik sense server 2.1). When I make a request (as openDoc for example), I have a html response instead of a json response. I guess it redirects me to the login homepage, but I think my credentials are correctly set (including certificate).

Please note that a call using QRS api works fine.

Could somebody give me some pointers ?

Here is the source code :

  • The post method

public class JsonRpcClient : HttpWebClientProtocol  

{      

      private int _id;      

      public virtual object Invoke(string method, params object[] args)      

     {           

          X509Certificate2 senseCert = new X509Certificate2("D:\\Qlik\\cert\\client.pfx");                      ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };           

          string xrfkey = "0123456789abcdef";                      

          HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://myserver/");

            request.Method = "POST";

            request.Accept = "application/json";

            request.Headers.Add("X-Qlik-xrfkey", xrfkey);

            request.ClientCertificates.Add(senseCert);

            request.Headers.Add("X-Qlik-User", @"UserDirectory=MYDIRECTORY;UserId=user");

            JObject j = new JObject(

                    new JProperty("jsonrpc", "2.0"),

                    new JProperty("id", ++_id),

                    new JProperty("method", method),

                    new JProperty("handle", -1),

                    new JProperty("params", args));

           // convert post data to a byte array.

            byte[] byteArray = Encoding.UTF8.GetBytes(j.ToString());

            request.ContentLength = byteArray.Length;

            // Get the request stream.

            Stream dataStream = request.GetRequestStream();

           // Write the data to the request stream.

            dataStream.Write(byteArray, 0, byteArray.Length);

           // Close the Stream object.

            dataStream.Close();

           // make the web request and return the content

            WebResponse response = request.GetResponse();

           Stream stream = response.GetResponseStream();

            var serializer = new JsonSerializer();

           var sr = new StreamReader(stream);

            var jsonTextReader = new JsonTextReader(sr);

            return sr.ReadToEnd();

        }

    }

  • the call

JsonRpcClient client = new JsonRpcClient();

client.Invoke("OpenDoc", copiedAppId, "MYDIRECTORY\user", "password", "", true);

  • the answer

"<!doctype html>\r\n<html lang=\"en\">\r\n<head>\r\n\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\r\n\t<title>Qlik Sense Login</title>\r\n\t<meta charset=\"utf-8\">\r\n\t<meta name=\"HandheldFriendly\" content=\"True\">\r\n\t<meta name=\"MobileOptimized\" content=\"320\">\r\n\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui\">\r\n\t<meta name=\"apple-mobile-web-app-capable\" content=\"yes\">\r\n\t<meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black\">\r\n\t<meta http-equiv=\"cleartype\" content=\"on\">\r\n\t<link rel=\"shortcut icon\" href=\"data:image/x-icon;base64,AAABAAEAQEAAAAEAIAAoQgAAFgAAACgAAABAAAAAgAAAAAEAIAAAAAAAAEIAABMLAAATCwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////EP///3L////A////7//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////...

<form autocomplete=\"off\" method=\"POST\" class=\"login-form\" id=\"login-form\">\r\n\t\t\t\t<label>User name</label>\r\n\t\t\t<input type=\"text\" name=\"username\" placeholder=\"domain\\user\" autofocus=\"autofocus\">\r\n\r\n\t\t\t\t<label>Password</label>\r\n\t\t\t\t<input type=\"password\" name=\"pwd\">\r\n\r\n\t\t\t<div id=\"error-message\" class=\"error-message\"></div>\r\n\t\t\t<input type=\"submit\" id=\"loginbtn\" value=\"Log in\" />\r\n\t\t\t</form>\r\n\t\t</div>\r\n\t<div class=\"background bottom-qlik-background\"></div>\r\n</body>\r\n</html>"

Thank you

Tags (2)
3 Replies
Employee
Employee

Re: Qlik Engine html response (C#)

Hmmm, it looks like you are doing a http request?

Qlik Sense uses websockets as its communication protocol with clients, not http.

I'm not a big C# guy but it looks like you are trying to post the json in the http body.

Luminary
Luminary

Re: Qlik Engine html response (C#)

Hi,

if you want to call the engine from .net just use the .NET SDK this is working very well.

If you like to access the repository api, use the REST Calls like you did.

bye

Konrad

Employee
Employee

Re: Qlik Engine html response (C#)

As Konrad Mattheis pointed out, the .Net SDK is the recommended way to work with Qlik Sense engine calls in a .Net environment. You can download it from NuGet (NuGet Gallery | Qlik Sense .Net SDK 2.1.1) or directly from the download section at www.qlik.com. More information about the Qlik Sense .Net SDK and instructions regarding downloading and how to get started can be found at the following location:

http://help.qlik.com/sense/2.1/en-US/developer/#../Subsystems/NetSDKAPI/Content/Introduction/Net-Sdk...