AnsweredAssumed Answered

Trouble in downloading WAS PDF report using C#

Question asked by VIKRAM GAIKWAD on Apr 3, 2013
Latest reply on Apr 4, 2013 by WillB



I have trouble in downloading report generated of a WAS scan using C#. The report gets downloaded to my machine, but when I try to open it, shows error as this file may be corrupted. I suspect that it is code written in C# to build the PDF file back. The same report if I download from GUI, opens and shows all data correctly.


Appreciate any help in correcting this!



private void createFile(string postData, string apiURL, string method)


            postData = "";

            apiURL = "";

            method = "get";

            req = (HttpWebRequest)HttpWebRequest.Create(apiURL);

            req.Method = method;

            byte[] authInfo = new UTF8Encoding().GetBytes(txtID.Text + ":" + txtPassword.Text);

            req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(authInfo);

            req.ContentType = "text/xml";

            if (!postData.Equals(""))


                Byte[] postBytes = Encoding.UTF8.GetBytes(postData);

                req.ContentLength = postData.Length;

                using (var dataStream = req.GetRequestStream())


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




            resp = (HttpWebResponse)req.GetResponse();



            Stream respStream = resp.GetResponseStream();



            string filename = "E:\\Getonline_service\\QualysAPI1\\QualysAPI\\QualysAPI\\newfile.pdf";

            FileStream fs = new FileStream(filename, FileMode.Create);



            String responseString = "";

            using (Stream stream = resp.GetResponseStream())


                StreamReader reader = new StreamReader(stream, Encoding.UTF8);

                 responseString = reader.ReadToEnd();




            byte[] array = Encoding.ASCII.GetBytes(responseString);

            fs.Write(array,0,array.Length -1);