[SOLVED] UHTTP Raw data

Author: i.sharp@pcisystems.co.uk (Iain Sharp)

I am trying to integrate with a third party application, they have a web format output, returning a PDF.  Entering the url in a browser prompts for user accreditation, and then begins a download and save of the PDF.  If I use UHTTP.GET(URL, User, Password,......) the returned data looks like the pdf file but encoded differently. (i.e. the first few characters are correct, as they are plain text, but thereafter the special characters are different. ) I am returning it to a raw variable Saving this output (filedump/raw) gives a file which cannot be read by adobe. I have run a comparison with the saved file from I.E. and they are different. The returned headers from the url are "Cache-Control=private·;Transfer-Encoding=chunked·;Content-Type=application/octet-stream·;Server=Microsoft-IIS/8.5·;Content-Disposition=attachment;filename=201502091359.pdf·;X-AspNet-Version=4.0.30319·;X-Powered-By=ASP.NET·;Date=Tue, 10 Feb 2015 12:05:30 GMT" and I pass no specific headers to the program.  Is there any way to get the raw output from UHTTP without any form of encoding, or to remove the encoding it provides? (a different character set in the original header? I don't think the character set has an effect on application/octet-stream. 

8 Comments

  1. Yes, nowadays, it's a real issue than we can't fetch raw data with uhttp. This is still a wish today : http://unifaceinfo.com/uhttp-to-be-able-to-grab-raw-data/ Because Response parameter is a string, it's impossible to get a simple pdf document : http://uniface.blogspot.be/2014/10/fetching-web-content.html Philippe


    Author: Philippe (philippe.grangeray@agfa.com)
  2. Philippe said Because Response parameter is a string, it's impossible to get a simple pdf document : http://uniface.blogspot.be/2014/10/fetching-web-content.html
    For me it is incomprehensible why this parameter is still a string.

    In my case, I had to build a new component to get/post raw content using OS component to call 'curl' (which is, partially, included in Uniface distribution).    


    Author: luis.vila (luis.vila@uniface.es)
  3. This is being worked on at the moment. It should be in the 9.6.07 update in May. 


    Author: Adrian Gosbell (adrian.gosbell@synapse-i.jp)
  4.  Did this get fixed in 9.6.07? We are still on 9.6.06, and whilst I can find updates to uhttp in the patch text files, none of them seem to specifically relate to this.  If it is fixed we need to update, but as this is a new release to all our customers, we don't want to unless it's fixed.  Iain


    Author: Iain Sharp (i.sharp@pcisystems.co.uk)
  5. Iain Sharp said  Did this get fixed in 9.6.07? We are still on 9.6.06, and whilst I can find updates to uhttp in the patch text files, none of them seem to specifically relate to this. 

    The following UHTTP enhancements have been added to Uniface 9.6.07/MX06 (for details see What's New in Uniface 9.6.07):

    You can now integrate Uniface applications and cloud-based data storage services such as Amazon, DropBox, Google Drive, and Microsoft OneDrive that provide REST-compliant APIs.

    To enable this, the Uniface UHTTP component has been enhanced to support binary file transport. The UHTTP component is Uniface's HTTP client and has operations that enable you to integrate communication with web sites (including REST-compliant services), implement basic browser functionality, and so on.

    The following operations have been added:

    • LOAD_FILE_CONTENTS—load a file, or part of a file, into the body of a request prior to calling SEND to upload to a REST API.
    • DUMP_FILE_CONTENTS—declare the response of a SEND operation as a full or partial file download from a REST API.
    • GET_INFO—get information about the about the body of the request or response, either before or after the SEND operation.
    • CLOSE_FILE—close the current file that was being used for chunked file transfer.

    More info about the new UHTTP operations can also be found here: Uniface Reference > APIs: Uniface Components > UHTTP Hope this helps. Daniel


    Author: diseli (daniel.iseli@uniface.com)
  6. None of those sound like the statement "The response from a GET operation may now be raw data, and will not be interpreted as a string...", so it's hard to know if it helps. 


    Author: Iain Sharp (i.sharp@pcisystems.co.uk)
  7. Iain Sharp said None of those sound like the statement "The response from a GET operation may now be raw data, and will not be interpreted as a string...", so it's hard to know if it helps. 

    The UHTTP SEND operation has not been changed: the Content parameter is still a String. If you want to (e.g.) download a binary file then you need to use the new operation DUMP_FILE_CONTENTS. Here's a small example that demonstrates how to download the PDF with the PAM for Uniface 9.6:

    variables     handle vUhttp     string vUrl, vHeaders, vResp endvariables

    newinstance "UHTTP", vUhttp vUrl = "http://unifaceinfo.com/download/4262/" vUhttp->SET_FLAGS(8)    ; GET send headers vUhttp->DUMP_FILE_CONTENTS("PAM96.pdf", "") vUhttp->SEND(vUrl, "GET", "", "", vHeaders, "", vResp) vUhttp->DUMP_FILE_CONTENTS("", "") For the sake of simplicity I've not included any error checking in the code. Hope this helps. Daniel


    Author: diseli (daniel.iseli@uniface.com)
  8. A new community sample Uniface UHTTP: Uploading files to Onedrive and downloading files from Onedrive has been added.  This sample also demonstrates how to use these new operations.   Kind regards Peter


    Author: PBeugel (peter.beugel@uniface.com)