web
You’re offline. This is a read only version of the page.
close
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,262

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.

I have the same question (0)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans