Bit of a .NET problem here as I am not a .NET programmer. I use Navision :)
I am using Navision to connect 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';
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! But if I build a basic web submit form to do this, 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>country:</td>
<input name="country" type="de">
</td>
</tr>
</tbody>
</table>
<input type="submit" value="Send" />
<input type="reset" />
</form>
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???
So my only guess is that the encoding of the STRING I stream out to the file is somehow wrong............ should there be some form of conversion I perform before/during saving the PDF???
Or are there better .NET classes I could be using to achieve the same effect without this problem?