Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problems Downloading binary file with HTTP_GET

Former Member
0 Likes
1,061

Hi Gurus!

I need to download a .ZIP file from internet, and write it in a specified path. After writing the file, I try to execute it, and I get a message that the file is corrupt. If I want to download a .TXT file, the operation works well.

Here is my code:


REPORT  z_http_test.


PARAMETERS : uri(100) LOWER CASE
DEFAULT 'http://www.sdn.sap.com/irj/boc/index?rid=/library/uuid/a0a1c942-2d81-2b10-48b5-a5ab5f35a5cb&overridelayout=true' .

PARAMETERS:  p_file_i    TYPE rlgrap-filename MEMORY ID filei OBLIGATORY default 'D:usrsapInterfacesdk.zip'.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file_i.

  DATA: vl_path LIKE  dxfields-longpath.

  CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
    EXPORTING
      i_location_flag = 'A'
      i_server        = ' '
      i_path          = 'D:usrsapInterfacesdk.zip'
      filemask        = '*.*'
      fileoperation   = 'R'
    IMPORTING
      o_path          = vl_path
    EXCEPTIONS
      rfc_error       = 1
      error_with_gui  = 2
      OTHERS          = 3.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    p_file_i = vl_path.
  ENDIF.

START-OF-SELECTION.

  DATA: status_code(5),
  status_text(300),
  len TYPE i.

  DATA: t_request_header TYPE TABLE OF sbcheader WITH HEADER LINE,
        t_request_body TYPE TABLE OF sbcbody WITH HEADER LINE,
        t_response_header TYPE TABLE OF sbcheader WITH HEADER LINE,
        t_response_body TYPE TABLE OF sbcbody WITH HEADER LINE,
        wa_response_body      LIKE LINE OF t_response_body.

  CALL FUNCTION 'HTTP_GET'
    EXPORTING
      absolute_uri                      = uri
*   REQUEST_ENTITY_BODY_LENGTH        =
*   RFC_DESTINATION                   =
*   PROXY                             =
*   PROXY_USER                        =
*   PROXY_PASSWORD                    =
*   USER                              =
*   PASSWORD                          =
     blankstocrlf                      = 'X'
*   TIMEOUT                           =
   IMPORTING
       status_code = status_code
       status_text = status_text
*   RESPONSE_ENTITY_BODY_LENGTH       =
    TABLES
       request_entity_body            = t_request_body
       response_entity_body           = t_response_body
       response_headers               = t_response_header
       request_headers                = t_request_header
   EXCEPTIONS
     connect_failed                    = 1
     timeout                           = 2
     internal_error                    = 3
     tcpip_error                       = 4
     data_error                        = 5
     system_failure                    = 6
     communication_failure             = 7
     OTHERS                            = 8
            .
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

* Open interface file
  OPEN DATASET p_file_i FOR OUTPUT IN BINARY MODE.

  IF sy-subrc <> 0.
  ELSE.

    LOOP AT t_response_body INTO wa_response_body.

      TRANSFER wa_response_body TO p_file_i.

    ENDLOOP.

  ENDIF.

  CLOSE DATASET p_file_i.

Any ideas what I´m doing wrong?

Thanks in advance.

Esteban

1 REPLY 1
Read only

Former Member
0 Likes
423

That's because you are putting data into CHAR table, plus  blankstocrlf  = 'X' - corrupts lines by putting CRLF in them

  • Take for example

DATA:   t_response_body    TYPE truxs_xml_table.

  • and

CALL FUNCTION 'HTTP_GET'

    EXPORTING

          blankstocrlf                      = ' '