您如何通过HTTP Post将参数值数组发送到SSRS?

时间:2018-09-18 16:40:57

标签: .net reporting-services

我正在尝试让SSRS生成PDF格式的报告并捕获字节流以将其保存到磁盘。如果我必须发送的唯一报告参数是单个值,则此方法很好,但是如果我必须发送特定参数的值数组,则它不再起作用。

由于我只发送“一年”值,因此下面的方法工作正常。通过用户界面,Year参数将成为多选。

        string parameters = "rs:Command=Render&rs:format=PDF&Year=2018"
        byte[] paramHeader = Encoding.ASCII.GetBytes(parameters);
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);
        req.PreAuthenticate = true;
        req.Credentials = new System.Net.NetworkCredential(
            reportUser,
            reportUserPW,
            reportUserDomain);

        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        req.ContentLength = paramHeader.Length;

        using (var stream = req.GetRequestStream())
        {
            stream.Write(paramHeader, 0, paramHeader.Length);
        }

            HttpWebResponse HttpWResp = (HttpWebResponse)req.GetResponse();
            Stream fStream = HttpWResp.GetResponseStream();
            File.WriteAllBytes(JobId.ToString() + "\\employeeName.pdf", copyStreamToByteArray(fStream));

如果我将参数字符串更改为具有多个Year值,则会失败:

string parameters = "rs:Command=Render&rs:format=PDF&Year=2018,2017,2016"

在使用Reports Services UI时,我尝试查看Web流量,以了解它如何通过Fiddler向SSRS发送参数,但无法从中获取任何有用的信息。看起来它已经编码为某种ViewState字符串。

如何在Post标头中发送给定SSRS参数的值数组?

1 个答案:

答案 0 :(得分:1)

要执行此操作,只需为每个其他值重复该参数,如下所示:

string parameters = "rs:Command=Render&rs:format=PDF&Year=2018&Year=2017&Year=2016"