Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

HttpClientRequest not returning the full response

Avatar

Avatar
Validate 1
Level 1
jferreira10
Level 1

Likes

2 likes

Total Posts

8 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
jferreira10
Level 1

Likes

2 likes

Total Posts

8 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
jferreira10
Level 1

28-05-2019

Hello,

My goal is to have a webform with a link for the client to download a PDF, this PDF should come from a HTTP request from a server in our network and I will display it via webform to the public.

I'm not able to receive the full response for a PDF on an HttpClientRequest, it seems that everytime the pdf is incomplete, if I try with a website URL the response is longer and ok, but never with PDF.

I've try all kinds of hearders but with no success.

Here's a sample of the code:

Code

var url = 'https://www.soundczech.cz/temp/lorem-ipsum.pdf';

var http = new HttpClientRequest(url);

http.method = "GET";

http.header["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36";

http.header["Accept"] = "application/pdf";

http.header["Content-Type"] = "application/pdf;charset=utf-8";

http.header["accept-encoding"] = "gzip, deflate";

http.execute();

logInfo(http.response.body);

pdf = http.response.body;;

The logInfo goes to web@default and the pdf is displayed on webpage.

Thanks for any help

View Entire Topic

Avatar

Avatar
Validate 1
Level 1
jferreira10
Level 1

Likes

2 likes

Total Posts

8 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
jferreira10
Level 1

Likes

2 likes

Total Posts

8 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
jferreira10
Level 1

28-05-2019

Hello,

I managed to do this in another way (will share how, in case more people need it).

I was using the code in a JavaScript and using a webApp variable to pass the content from the JS to the page item.

This was solved by executing the javascript code in the page itself.

Apparently we can't store the result of a PDF in a var because there are some EOF text that can corrupt the result. So the final code is:

<head>

<%

var url = 'https://www.soundczech.cz/temp/lorem-ipsum.pdf';

var http = new HttpClientRequest(url);

http.method = "GET";

http.execute();

%>

</head>

<body style="" class="">

<p>Stuff:</p>

<a href="data:application/pdf;base64, <%= http.response.body.toBase64() %>" target="_blank" download=""> pdf </a>

This will enable the user to download the PDF.