Programming Languages on Power

Power Programming Languages

IBM Power, including the AIX, IBM i, and Linux operating systems, support a wide range of programming languages, catering to both traditional enterprise applications and modern development needs.


#Power

 View Only
  • 1.  QSYS2.HTTP_POST Unreadable Fedex Response

    Posted 06/10/26 03:48 PM

    I'm trying to run the code below which is supposed to create an error. The 2nd parameter of the QSYS2.HTTP_POST command is blank. The header authorization is also blank. I'm expecting an error such as 'No access token provided' to appear in my response file upu178shiprm.txt.

    Instead, I get what appears to be garbage in my response file upu178shiprm.txt which is pasted below.

    The replystmf is defined as a clob_file. I've also defined replystmf as 'sqltype(clob_file) ccsid(1208)' and 'sqltype(clob_file) ccsid(37)'.

    D replystmf       s                   sqltype(clob_file)

    Does anyone have any thoughts on what is causing the unreadable response and what needs to be done to correct it?

    I have other code where I'm successfully retrieving an authorization token from Fedex, sending the authorization token and data to the Fedex Ship API below, and still receiving an unreadable response. It's a different response than what is pasted below but still unreadable.

    Any help would be appreciated. Thanks, Doug.

    0182.00  /free
    0183.00   replystmf_Name = '/xxxxxxxx/upu178shiprm.txt';
    0184.00   replystmf_NL   = %len(%trimr(replystmf_name));
    0185.00   replystmf_FO   = SQFOVR;
    0186.00    Exec Sql
    0187.00     VALUES QSYS2.HTTP_POST(
    0188.00               'https://apis-sandbox.fedex.com/ship/v1/shipments',
    0189.00                ' ',
    0190.00               '{"headers":{'
    0191.00               || '"content-type":"application/json",'
    0192.00               || '"authorization":" ",'
    0193.00               || '"ssltolerate":"true",'
    0194.00               || '"x-locale":"en-US"'
    0195.00               || '}}')
    0196.00               into :replystmf;
    0197.00  /end-free
    0198.00 C*

    Fedex Response (upu178shiprm.txt)

    ‹      ÿÊÁ
    ‚@ Ð_æœ"¦äz
    ò'!v):L»£H¹[»k â¿'¼½%íHúÞèRa(„ŒHì8H3±
    '8‚,‰·"´ªe'    …dku˜ßf"F1æxªšpiŽU]^‹CXÔuU¯q`ç¨û $åJðæÉÞÖ|{Å*„ó‹É1 Fõí"-XþŒì<VàíÔQ¯C\îËYZö›´  



    ------------------------------
    Doug Freeman
    ------------------------------


  • 2.  RE: QSYS2.HTTP_POST Unreadable Fedex Response

    Posted 06/11/26 01:26 AM

    When i add https:// to your URL, I receive something unreadable, too.

    Putting HEX() around it:

     

    1F8B08000000000000FF1DCABD0AC2301000E057396EB6C5FA1BBA090A76B15274511CAEB96B09DA44935428E2BB5B1C3FF83E183DD9403A1A670BC61C70BE2661D5CC9375AD66C962D5AC927AAAB3A4CE966AA1B856B2649CA078EF7CC0FCFA41ED5830C743794A37E7D3BEAC8ACB6E9BEEAAAAACC6D84908D4FE8303D27A244477170B4FEFDE868553383E848240E7D834030CAEF7E0E5D54B88409621FA01A8256353FCDEBE3F57151660B4000000

     

    That's interesting, because when you try the URL in the browser, you get what you expect:
    {"transactionId": "b470ab0f-9cc2-4cfb-81b7-b45d0539abc9","errors":[{"code":"NOT.AUTHORIZED.ERROR","message":"No access token provided. Please modify your request and try again."}]}

    That response is 176 bytes long. According to the Content-Length header in the response. (F12 Network In the browser)

     

    The hex sequence is 176 bytes long, too. But it makes no sense in any encoding I tried.

     

    Aha! The readable answer above is in fact 180 bytes long!

    The response header in the browser says it's gzip encoded.

     

    And yes, that might be the case, although the compressing 180 bytes to 176 bytes isn't that impressive.

    https://en.wikipedia.org/wiki/Gzip

    A gzip sequence starts with x'1F8B08'.

     

    Adding "accept-encoding: identity" to the headers didn't change anything.

     

    So I guess you have several choices.

    Maybe there's a way force the fedex server to not gzipping the answer

    Maybe IBM is able to unzip the answer – If you figure that out, let us know it, too, please.

     

    You somehow ungzip the answer yourself – if you do that, please let us know, how.

     

    best regards,

    Anton Gombkötö

     






  • 3.  RE: QSYS2.HTTP_POST Unreadable Fedex Response

    Posted 06/11/26 10:25 AM

    Sorry  Anton, didn't see your post until I responded (still early here 😉).
    Yes, what Anton said 😁



    ------------------------------
    Patrick Behr
    Senior Consultant
    Seiden Group
    OR
    ------------------------------



  • 4.  RE: QSYS2.HTTP_POST Unreadable Fedex Response

    Posted 06/11/26 10:58 AM

    Who could possibly feel offended being confirmed by a champion like Patrick? 😊

    Who also happened to solve the unzipping problem, which I couldn't.

    But is that possible in memory, too?
    (And I still see no sense in passing the content zipped as it is to the consumer. Might be worth an IDEA.)

     

    Best regards,

    Anton Gombkötö

     






  • 5.  RE: QSYS2.HTTP_POST Unreadable Fedex Response

    Posted 06/11/26 11:21 AM

    I didn't go past confirming the original problem 🤪
    Didn't try to figure out if there's some sort of issue in the SQL or axis programs, and didn't check for existing solutions.
    The problem is understood, so an issue/idea and a workaround should be within reach 😁



    ------------------------------
    Patrick Behr
    Senior Consultant
    Seiden Group
    OR
    ------------------------------



  • 6.  RE: QSYS2.HTTP_POST Unreadable Fedex Response

    Posted 06/11/26 10:04 AM

    The response is GZIPed, so it's binary (a blob, not a clob).
    Tried requesting an uncompressed response ("Accept-Encoding": "identity") but FedEx did not comply.
    Unrelated issue is that sslTolerate is not a header and should be included in the "options" parm but not inside "headers" object.  Also, true (the Boolean) is not the same at "true" the string.
    Also unrelated but sslTolerate is OK for a little testing but please get the certificate installed and validate.

    We can download the binary response:
    call ifs_write_binary( 
        path_name => '/some/path/test_fedex_blob.json.gzip',
        line => (
            values qsys2.http_post_blob(
                url => 'https://apis-sandbox.fedex.com/ship/v1/shipments',
                request_message => '',
                options => '{"sslTolerate":true, "headers":{"content-type":"application/json", "authorization":"", "x-locale":"en-US", "Accept-Encoding": "identity"}}'
            )
        )
    )

    And then if you gunzip that (i.e. in bash), you'll get the JSON file.



    ------------------------------
    Patrick Behr
    Senior Consultant
    Seiden Group
    OR
    ------------------------------



  • 7.  RE: QSYS2.HTTP_POST Unreadable Fedex Response

    Posted 06/12/26 12:41 PM

    Thank you Anton, Patrick, and John (privately) for responding.

    I wanted to follow up. I added the following header line to my code:

                                        || '"content-encoding":"gzip",'

    and I can receive a readable response from Fedex which I've pasted below. I believe I've been getting this 'Invalid GZIP' message all along but have not been able to read it. I captured the axis.log yesterday and it showed a HTTP 400 Bad Request so I have work to do.

    Thanks again for the help. Doug.

     <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Body>
            <soapenv:Fault>
                <faultcode>soapenv:Server</faultcode>
                <faultstring>Invalid GZIP compressed request</faultstring>
                <faultactor>https://apis-sandbox.fedex.com:443/ship/v1/shipments</faultactor>
            </soapenv:Fault>
        </soapenv:Body>
    </soapenv:Envelope>



    ------------------------------
    Doug Freeman
    ------------------------------



  • 8.  RE: QSYS2.HTTP_POST Unreadable Fedex Response

    Posted 28 days ago
    Edited by Paul Nicolay 28 days ago

    (removed my previous answer as the https was included).

    BTW, it seems that Fedex is ignoring Accept-Encoding and Accept headers so the only solution is to unzip the reply.

    PS. /free and /end-free are no longer required in RPG.



  • 9.  RE: QSYS2.HTTP_POST Unreadable Fedex Response

    Posted 28 days ago

    Paul,

    i fell into the same trap, the links contains the https, but the textual representation in the mail doesn't.

     

    Doug,

    great find!

    Yes, adding the header info that the request is gzipped makes the IBM i unzipping the response!

     

    That's more than weird; it's just wrong in my opinion.
    IBM might be questioning the wrong header, which makes life pretty complicated if one has to send uncompressed requests and has to process compressed responses.

     

    Thanks,

    Best regards

    Anton Gombkötö