accept-encoding gzip issue with call "*plus/web/request"

Started by Cedric, May 09, 2024, 04:30:25 PM

Previous topic - Next topic

Cedric

Hi, I would like to report 1 issue that I have juste encountered:

Unable to read compressed data like gzip for example.  Normally, I would specify in the header "accept-encoding: none" and it would result in a non compressed response, but on this particular server, it seems they force the response in gzip no matter what I do.  So, now I have to figure out how to handle this in PVX!

Mike King

If you need to provide the content type to the request you can pass it in as the fifth parameter to *plis/web/request.

See https://manual.pvxplus.com/PXPLUS/Web%20Services/Overview.htm#submitting

To compress data use the CMP() function and strip the first byte as per the manual.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

Mike King

Further info...

If you need to decompress data in a response prefix the data with a $00$ then pass it to the UCP function.

See https://manual.pvxplus.com/PXPLUS/functions/ucp.htm for details
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

Cedric

Thanks Mike, the info is helpful, but unfortunately the UCP solution throws an error 46.
I've tried with prefix, without, with other like $01$, $02$, etc... Always the same...

I'm thinking it may be related to the error 29 I'm getting while trying to simply print the data to screen.


Anyway, for now, I was able to reach out to the server admin so that I can receive the data uncompressed.


thanks

Mike King

Glad to hear you got it to work.

Perhaps the data is nt only gzip'ed but also Base64 encoded which would be common where binary data, such as what would be in the zipped contents, is involved.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

Stéphane Devouard

Cedric

Here is the code I use on Linux to ungzip content returned by some APIs we're working with :


0780 UNGZIP:
0790 ENTER (GZIPPED$)
0800 !
0810 UNGZIPPED$=""
0820 !
0830 GZFILE$="/tmp/pvx/TEMP."+FID(0)+"."+DTE(0:"YYYYMMDD.%Hz%mz%sz")+".gzip"
0840 OPEN CREATE PURGE (HFN,ISZ=-1,ERR=*NEXT)GZFILE$
0850 IF TCB(2)=1 THEN RETURN ""
0860 WRITE RECORD (LFO,SIZ=LEN(GZIPPED$),ERR=*NEXT)GZIPPED$; GZIPPED$=""
0870 CLOSE (LFO)
0880 FOR (GZIPPED$="")
0890 OPEN (HFN,ERR=*BREAK)"<cat "+GZFILE$+"|gzip -d"
0900 UNGZIPPED$+=RCD(LFO,END=*NEXT); GOTO *SAME
0910 CLOSE (LFO)
0920 ERASE GZFILE$,ERR=*NEXT
0930 NEXT
0940 !
0950 RETURN UNGZIPPED$


Hope this helps
Stéphane Devouard
Portfolio | Work