Search code examples
phpiiscompressionhttprequestabap

http request from ABAP to IIS 10 remains zipped when processed in PHP


We are sending XML-files from ABAP to IIS 10-webserver by http-request which is processed by PHP. Uncompressed sent data works well, but if I switch on compression in ABAP, PHP receives scrambled (binary compressed?) data, which is much smaller than the original data, so I think it remains compressed. According to my understanding the IIS should uncompress the data before giving it to PHP, so I shouldn't care about this thing.

ABAP code for sending request

method send_xstring_by_https.     
     data string_content type string.
     do 200 times.
        string_content = |{ string_content }this is an example XML - some Umlauts: üöä.|.
     enddo.

     "Content gets the type xstring
     content = cl_abap_codepage=>convert_to( source = |<?xml version="1.0" encoding="iso-8859-1"?><someData>{ string_content }</someData>|
                                             codepage = |ISO-8859-1| ).
     DATA: o_client TYPE REF TO if_http_client.

     cl_http_client=>create_by_url( EXPORTING
                                      url     = |<your_url>|
                                    IMPORTING
                                      client  = o_client ).


     o_client->request->set_version( version = if_http_request=>co_protocol_version_1_1 ).
     o_client->request->set_method( if_http_request=>CO_REQUEST_METHOD_GET ).
     o_client->request->set_content_type( 'text/xml; charset=ISO-8859-1' ).
     data(length_content) = xstrlen( content ).
     o_client->propertytype_accept_compress = if_http_client=>co_enabled.
***     "Compression remove *** to set compression
***     o_client->set_compression( if_http_client=>co_compress_in_all_cases ).
     o_client->request->SET_DATA(
       exporting
         DATA               = content    " Binary Data
         LENGTH             = length_content    " Length of Binary Data
     o_client->send( if_http_client=>co_timeout_default ).

     o_client->receive( EXCEPTIONS
                          HTTP_COMMUNICATION_FAILURE = 1
                          HTTP_INVALID_STATE = 2
                          HTTP_PROCESSING_FAILED = 3
                      ).
  endmethod.

PHP-code for receiving

<?php
    $content = file_get_contents('php://input');

    if (!file_put_contents(<local_path_and_filename>, $content)) {
        echo "ERROR";
    }
?>

The example will send uncompressed data, to send compressed data, remove the ***. It creates a long xml file, if the xml is to short, it seems it will be never compressed. Try to set the loop to 1 times and compression on for testing.

I looked for compression settings for received requests, but found none. The only settings for compression I found are for sending requests by IIS, which I switched on (dynamic and static compression).

I tried some different content types, like e.g. application/XML, but doesn't work.

Editing 23:43: Isn't the way it should work the following:

  • abap-request sets uncompressed content
  • SAP-Netweaver sends the request and is allowed for sending compressed content.
  • SAP-Netweaver contacts the IIS-Server and they negotiate if and what method for compression is to use
  • SAP-Netweaver sends compressed request
  • IIS receives compressed request and uncompress it
  • PHP gets uncompressed data

Thinking of this process I don't know what to change in my PHP-Code


Solution

  • I found a workaround for my problem.

    I try to decompress the content in the PHP script. If decompression is not possible, the content will be write to file directly. That worked for me:

        $receivedContent = file_get_contents('php://input');
        $contentToWrite = gzdecode($receivedContent);
        if (!$contentToWrite) {
            $contentToWrite = $receivedContent;
        }
        if (!file_put_contents(<local_path_and_filename>, $contentToWrite)) {
            echo "ERROR";
        }