Using HttpClient and WebClient to retrieve content of drill down report

Viewed 99

I'm using httpclient to load SSRS report from server, the ssrs report link is long an contain empty spaces in report name special characters and so on

exp(http://server/ReportServer_ssrs?/folder/folder_some_folder_new/test/Drilldown - Some report Name (500)&session=session&languageID=1033&dateSelection=13&begDate=08/04/2022 00:00:00&endDate=08/04/2022 00:00:00&rc:Toolbar=False ...):

var clientHandler = new HttpClientHandler { CookieContainer = cookieContainer, ,Credentials=NetworkCredentials};

   using (var client = new HttpClient(clientHandler))
    {                         
          var content= await client.GetStringAsync(reportUrl);
    }

the problem is that when i use HttpCilent it throws error with:

 Response status code does not indicate success: 500 (Reporting Services Error).

inner exception is null, but if i use same url with WebClient

 using (WebClient webClient = new WebClient())
 {
    webClient.Credentials = NetworkCredentials;
    content= webClient.DownloadString(reportUrl);
}

the content is returned and everything is ok. I guess that something is wrong with the report url, i have tried to use Uri.EscapeDataString, Uri.EscapeString but without success always with HttpClient i get error 500.

I do not want to use webclient since is obsolete and even VS state use HttpClient instead, but obviously i'm doing something wrong, webclient somehow know how to get the report.

Any suggestion appreciated

0 Answers
Related