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;
<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>
%PDF-1.4 %???? 3 0 obj <</Type/XObject/ColorSpace/DeviceGray/Subtype/Image/BitsPerComponent 8/Width 227/Length 30/Height 35/Filter/FlateDecode>>stream x???
Array := Convert.FromBase64String(ResponseData); MemoryStream := MemoryStream.MemoryStream(Array); TempBlob.Blob.CREATEOUTSTREAM(OutStream); MemoryStream.WriteTo(OutStream); TempBlob.Blob.EXPORT('Output.PDF'); VARs as follows... Convert DotNet 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Convert Array DotNet 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Array MemoryStream DotNet 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.MemoryStream OutStream OutStream TempBlob Record TempBlobP.S. In newer versions of NAV you should use the BlobExport function in codeunit 319 "3-Tier Automation Mgt" to export data from the Blob field
Answers
P.S. In newer versions of NAV you should use the BlobExport function in codeunit 319 "3-Tier Automation Mgt" to export data from the Blob field
I coded it and ran it and the message I got was:
"A call to FromBase64String failed with this message: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters".
And your code above gave me the clue.
Instead of reading it in now with ReadAsStringAsync I used your code above and read ReadAsByteArrayAsync into your ARRAY variable.
I then simply deleted the CONVERT code and did the rest and the file produced by this saved perfectly.
So now I know HOW to do it I would like to know WHY it works. Can someone explain to me the difference between reading the response into text and streaming it out to a file.... and streaming it to Blob and exporting a file?
I guess something somewhere is encoded differently? But what, how and why?