Search code examples
c#restapicognossiteminder

How get cognos report using siteminder token in c#.net


I am trying to get cognos report using siteminder token, below is my code.

string cognosUrl = "https://cognos.blah.com";

string reportPath = "/c10/cgi-bin/cognosisapi.dll/rds/reportData/report/";                   string reportId = "ildjfsldkf"; //prod
cognosUrl += string.Concat(reportPath, reportId,"?blahblah");
string targetUrl = cognosUrl;
string strFormvalues = string.Concat("TARGET=",targetUrl);
ASCIIEncoding encoder = new ASCIIEncoding();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(targetUrl);
byte[] data = encoder.GetBytes(strFormvalues);
request.AllowAutoRedirect = false;
request.Timeout = 120000;
request.ContentLength = data.Length;
request.ContentType = "text/xml;charset=\"utf-8\"";
request.Method = "POST";
request.Headers.Add(HttpRequestHeader.Cookie,"SMSESSION="+stoken);
request.GetRequestStream().Write(data, 0, data.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string json = reader.ReadToEnd();
byte[] byteArray = Encoding.UTF8.GetBytes(json);
MemoryStream restream = new MemoryStream(byteArray);
using (Stream output = File.OpenWrite(@"c:\\Projects\\Test_"+DateTime.Now.ToString("yyyyMMddHHmmssfff")+".txt"))
                using (Stream input = restream)
                {
                    if (input != null) input.CopyTo(output);
                }
                // var results = serializer.DeserializeObject(json);
                reader.Close();
                dataStream.Close();
                response.Close();

But I am getting response as " DPR-ERR-2101 Your request was invalid.Please contact your administrator."


Solution

  • I am not using C# myself, but a few recommendations while debugging this:

    • If you are only posting a URL, why not use GET instead of POST?
    • Try paste the targetURL in your browser, see what happens.
    • In my setup, when I paste the URL in the browser, I am always redirected before I receive an answer. (to a URL like, /cgi-bin/cognosisapi.dll/rds/sessionOutput/conversationID/i292ED29A62474697AD44306A388F5BBB You are preventing that to happen, that might be an issue)

    Hope that helps.