Search code examples
javascriptpostinternet-explorerabap

Internet Explorer don't POST


I am working on a SAP interface project, in which the standard call is usually the Internet Explorer. I am trying to gather the information processed by HTML within the IE and send it to SAP using the following code:

REPORT demo_html_input.

INCLUDE: ZCAS_TEXT_POST_HTML_SRC.

TYPES: typ_html_code TYPE TABLE OF char255 WITH EMPTY KEY,
       typ_source    TYPE TABLE OF string.

CLASS html_start DEFINITION.
  PUBLIC SECTION.
    METHODS: constructor,
             txt_html RETURNING VALUE(lt_codigo) TYPE string.
  PRIVATE SECTION.


    data: lv_html_code type string.
    METHODS: get_source,
             descomented
             IMPORTING
               lt_source    TYPE typ_source
             EXPORTING
               lv_html_code TYPE string.

ENDCLASS.

CLASS html_start IMPLEMENTATION.
  METHOD constructor.
    get_source( ).
  endmethod.

  METHOD txt_html.
    lt_codigo = lv_html_code.
  ENDMETHOD.

  METHOD get_source.
    DATA: lt_source TYPE TABLE OF string.

    CALL METHOD cl_reca_rs_services=>get_source
      EXPORTING
        id_objtype = 'PROG'
        id_objname = 'ZCAS_TEXT_POST_HTML_SRC'
      IMPORTING
        et_source  = lt_source.

    descomented( EXPORTING
                        lt_source = lt_source
                       IMPORTING
                         lv_html_code = lv_html_code ).
  ENDMETHOD.


  METHOD descomented.
    DATA: ls_html_code TYPE char255.
    DATA: ls_source TYPE string.

    DATA: lv_len_data TYPE i,
          lv_len_source TYPE i,
          lv_len_total TYPE i,
          lv_str_max  type i,
          lv_string TYPE string.

    LOOP AT lt_source INTO ls_source.
      TRY .
          ls_source = ls_source+1.
        CATCH cx_sy_range_out_of_bounds.
      ENDTRY.


      SHIFT ls_source RIGHT DELETING TRAILING ' '.
      SHIFT ls_source LEFT DELETING LEADING ' '.

      lv_string = ls_source .
      CONCATENATE lv_html_code lv_string INTO lv_html_code.
    ENDLOOP.
  ENDMETHOD.

ENDCLASS.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
  PRIVATE SECTION.
    CLASS-METHODS handle_sapevent
      FOR EVENT sapevent
                  OF cl_abap_browser
      IMPORTING action
                  query_table.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.
    DATA error_list TYPE cl_abap_browser=>html_table.

    SET HANDLER handle_sapevent.

    DATA: retorncode TYPE REF TO html_start.

    CREATE OBJECT retorncode.

    DATA(html_str) = retorncode->txt_html( ).

    cl_abap_browser=>show_html(
      EXPORTING
        html_string = html_str
        title       = 'Input Demo'
      IMPORTING
         html_errors = error_list ).

    IF error_list IS NOT INITIAL.
      MESSAGE 'Error in HTML' TYPE 'I' DISPLAY LIKE 'E'.
    ENDIF.
  ENDMETHOD.
  METHOD handle_sapevent.
    BREAK-POINT.
    DATA(out) = cl_demo_output_stream=>open( ).
    SET HANDLER cl_demo_output_html=>handle_output FOR out.
    out->write_data( iv_name = 'ACTION'      ia_value = action ).
    out->write_data( iv_name = 'QUERY_TABLE' ia_value = query_table ).
    out->close( ).
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  demo=>main( ).

In the ABAP call, any information sent to the URL with the prefix SAPEVENT: is redirected to the handle_sapevent method. I based myself on this code, which also works using IE;

https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abenhtml_input_abexa.htm

and I used this HTML:

<!DOCTYPE html>
<html lang="pt-br">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=9" />
    <title>Document</title>
</head>

<body>
    <input type="button" id="btn" onclick="">

</body>

<script>
    document.getElementById('btn').addEventListener('click', function sendTOAbap(ev) {

        var oOutput = document.querySelector("div"),
            oData = {
                campo: "sucesso",
                field: "insucesso"
            };

        oData.append("CustomField", "This is some extra data");

        var oReq = new XMLHttpRequest();
        oReq.open("POST", "SAPEVENT:SAPEVENT", true);
        oReq.onload = function (oEvent) {
            if (oReq.status == 200) {
                console.log("Uploaded!");
            } else {
                console.log("Error " + oReq.status + " occurred when trying to upload your file.");
            }
        };

        oReq.send(oData);
        ev.preventDefault();
    }, false);
</script>

</html>

The problem is that when I try to run it specifically using Internet Explorer, it returns an "access denied" or "not transported" error. I cannot change the browser version as it is the SAP standard. Tankyou to help-me.

I tried changing the access policies and changing the post methods, and changing the body.


Solution

  • i found outher alternative to make a post without char limits in a constructor make true query_disable, ou will do dump, and

    var prefixSendAbap = "SAPEVENT:SEND";
    
    var form = document.createElement('form');
    form.method = 'POST';
    form.action = prefixSendAbap;
    document.body.appendChild(form);
    
    var formField = document.createElement('input');
    formField.type = 'hidden';
    formField.name = 'ContentJson';
    formField.value = json;
    
    form.appendChild(formField);
    
    form.submit();
    
    /* Delete Node */
    document.body.removeChild(form);