如何使用WebRequest获取SSRS报告?

时间:2018-09-05 07:36:27

标签: c# reporting-services xmlhttprequest httprequest httpwebrequest

我总是使用我的代码获取空的XML文件,并从Web浏览器(Chrome)运行url时获取填充的XML文件。 两种情况下的网址都是相同的(具有相同的参数)...字符串day&month =“ 05”&“ 09”

string period = "From="+day+"/"+month+"/2018%2007:00:00&To="+day+"/"+month+"/2018%2009:00:00";
string response = doRequest(@"http://localserver/ReportServer?%2FSpecial%2FReport&"+period+"&rs:Format=XML");

private string doRequest(string url_with_params){

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url_with_params);
 request.UseDefaultCredentials = true;
 request.PreAuthenticate = true;
 request.Credentials =  new NetworkCredential("login", "password");

 using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  {
   if (response.StatusCode == HttpStatusCode.OK)
        {
            string responseText ="";
            using(var reader =  new System.IO.StreamReader(response.GetResponseStream())){
                responseText = reader.ReadToEnd();
            };
            return responseText;
        }
        response.Close();
        return null;
  }
}

我运行代码的XML文件如下:

<?xml version="1.0" encoding="utf-8"?><Report xsi:schemaLocation="Special_x0020_Report http://localserver/ReportServer?%2FSpecial%2FReport&amp;rs%3AFormat=XML&amp;rc%3ASchema=True" Name="Special Report" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="Special_x0020_Report"><Tablix1 /></Report>  

从浏览器运行:

<?xml version="1.0" encoding="utf-8"?><Report xsi:schemaLocation="Special_x0020_Report http://localserver/ReportServer?%2FSpecial%2FReport&amp;rs%3AFormat=XML&amp;rc%3ASchema=True" Name="Special Report" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="Special_x0020_Report"><Tablix1 /><Details_Collection>

<Details Name="Single" Qty="1" FailureCode="@BLOCK"/></Details_Collection></Report>      

0 个答案:

没有答案