Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Webresponse doesn't receive the hole PDF document

(0) ShareShare
ReportReport
Posted on by 3,221

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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,884 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,758 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans