Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 72043

Webresponse doesn't receive the hole PDF document

$
0
0

Hi

This webrequest with basic authentication should get a PDF document. But the response doesn't get the hole file. So there is a damaged error when opening in PDF Reader.

static void CallScmPdf(Args _args)
{
    System.Net.HttpWebRequest   webRequest;
    System.Net.HttpWebResponse  webResponse;
    System.IO.Stream            stream;
    System.IO.StreamReader      streamReader;
    System.IO.FileStream        fileStream;
    System.IO.StreamWriter      streamWriter;
    System.Text.UTF8Encoding    encoding;
    FileIOPermission            fioPermission;
    str                         webUrl, pdfStr;
    str                         path = @"c:\temp\Test.pdf";

    webUrl = 'https://test.repmgr.somedomain.ch/sc.repair.attachment/repair/attachment/abcdefg/data';

    webRequest = System.Net.WebRequest::Create(webUrl) as System.Net.HttpWebRequest;
    webRequest.set_Credentials(new System.Net.NetworkCredential('Usr', 'pass'));

    webResponse = webRequest.GetResponse();
    //webResponse.set_ContentType('application/octet-stream'); application/pdf

    encoding = new System.Text.UTF8Encoding();

    stream = webResponse.GetResponseStream();
    streamReader = new System.IO.StreamReader(stream, encoding);
    pdfStr = streamReader.ReadToEnd();

    fioPermission = new FileIOPermission(path, "RW");
    fioPermission.assert();

    streamWriter = new System.IO.StreamWriter(path, false, encoding);
    streamWriter.Write(pdfStr);

    info(pdfStr);

    streamReader.Close();
    stream.Close();
    webResponse.Close();
    streamWriter.Flush();
    streamWriter.Close();

}

Any idea why what can be done?

Thanks.


Viewing all articles
Browse latest Browse all 72043

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>