Options

HTTP Post Webresponse gives empty PDF

MauddibMauddib Member Posts: 269
edited 2016-10-20 in NAV Three Tier
Hi all,

I am connecting to a Webservice that returns a PDF. The code I am using is below.
HttpClient := HttpClient.HttpClient();

SubmitData := 'partnerid=MY1003';
SubmitData += '&password=mc1222';
SubmitData += '&country=DE';
SubmitData += '&firstname=Me';
SubmitData += '&lastname=McMe';
SubmitData += '&street=Thisstrasse';
SubmitData += '&housenumber=9';
SubmitData += '&zipcode=63741';
SubmitData += '&city=Aschaffenburg';

HttpContent := HttpContent.StringContent(SubmitData, Encoding.UTF8, 'application/x-www-form-urlencoded');
HttpResponseMessage := HttpClient.PostAsync(Uri.Uri('https://api-return-pdf.theirwebsite.com/PDFService/V1/getPDF'), HttpContent).Result;

IF (HttpResponseMessage.IsSuccessStatusCode) THEN BEGIN

  ResponseData := HttpResponseMessage.Content.ReadAsStringAsync().Result;
  f.CREATEOUTSTREAM(fileoutstream);
  fileoutstream.WRITETEXT(ResponseData);  

END;

The problem is however that the PDF returned appears to be entirely empty!!! However if I build a basic web submit form (also below as code) the PDF returned is perfect.
<form action="https://api-return-pdf.theirwebsite.com/PDFService/V1/getPDF" method="POST">
 <table>
 <thead></thead>
 <tbody>
 <tr>
 <td>User, Pass</td>
 <td><input name="partnerid" type="text">
 <input name="password" type="text">
 </td>
 </tr>
 <tr>
 <td>Vorname, Nachname</td>
 <td><input name="firstname" type="text">
 <input name="lastname" type="text">
 </td>
 </tr>
 <tr>
 <td>Firma:</td>
 <td><input name="company" type="text"></td>
 </tr>
 <tr>
 <td>Zusatz Adress Info</td>
 <td>
 <input name="additionalinfo" type="text">
 </td>
 </tr>
 <tr>
 <td>Strasse, Nr.</td>
 <td><input name="street" type="text">
 <input name="housenumber" type="text">
 </td>
 </tr>
 <tr>
 <td>PLZ, Stadt, country:</td>
 <td><input name="zipcode" type="text">
 <input name="city" type="text">
 <input name="country" type="de">
 </td>
 </tr>
<tr>
 <td>Kundenreferenznummer</td>
 <td>
 <input name="kdrefno" type="text">
 </td>
 </tr>
- 15 -
 </tbody>
 </table>
 <input type="submit" value="Send" />
 <input type="reset" />
</form>

Therefore I can only surmise that I am damaging the PDF file by saving it to a string and then to a FILESTREAM. Is there a more correct way I should be reading and saving the file that is returned in the response?

When I edit the resulting PDF in NOTEPAD I see the following at the beginning which LOOKS like a correct PDF to me.....
%PDF-1.4
%????
3 0 obj
<</Type/XObject/ColorSpace/DeviceGray/Subtype/Image/BitsPerComponent 8/Width 227/Length 30/Height 35/Filter/FlateDecode>>stream
x???

............ should there be some form of conversion I perform before/during saving the PDF???

Best Answers

Answers

Sign In or Register to comment.