Skip to sidebar Skip to content
Ipercube Technical
Jack of all trades, master of none
Date: Time: - Stardate:
Welcome, Log in by clicking  Here!
SS64
MDN
Stack
Code
GitHub
Wiki
Convert
V Studio
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions
Ipercube Technical
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions

HTTP Properties Get – Get properties of a file on a web server

This function use the PROPFIND method of HTTP 1.1 protocol to retrieve the properties of a file on a web server.

ABAP
FUNCTION z_http_property_get.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(URI) TYPE  STRING
*"     VALUE(PROP_NAME) TYPE  STRING OPTIONAL
*"  EXPORTING
*"     VALUE(PROP_VALUE) TYPE  STRING
*"     VALUE(CODE) TYPE  I
*"     VALUE(REASON) TYPE  STRING
*"  TABLES
*"      TAB_PROP STRUCTURE  SMUM_XMLTB OPTIONAL
*"  EXCEPTIONS
*"      NO_LOGIN_ACCOUNT_AVAILABLE
*"      HTTP_COMMUNICATION_FAILURE
*"      HTTP_INVALID_STATE
*"      HTTP_PROCESSING_FAILED
*"----------------------------------------------------------------------
*    Proof of Concept by IperCube 2007
*"----------------------------------------------------------------------

  DATA: user TYPE string,
        pwd TYPE string,
        x_bytes TYPE i.

* Set User/Password Logon to web server
  user = 'my_user'.
  pwd  = 'my_password'.
  
* Translate URL
  TRANSLATE uri USING ' *'.
  REPLACE ALL OCCURRENCES OF '*' IN uri WITH '%20' IN CHARACTER MODE.

******************************************************************
* Build XML request 
******************************************************************

  DATA: xml_table        TYPE TABLE OF smum_xmltb,
        wa_xml_table     TYPE smum_xmltb,
        xml_output       TYPE string.

* Ask for all properties
  wa_xml_table-hier = 1.
  wa_xml_table-type = 'V'.
  wa_xml_table-cname = 'propfind'.
  wa_xml_table-cvalue = ''.
  APPEND wa_xml_table TO xml_table.

  wa_xml_table-hier = 1.
  wa_xml_table-type = 'A'.
  wa_xml_table-cname = 'xmlns'.
  wa_xml_table-cvalue = 'DAV:'.
  APPEND wa_xml_table TO xml_table.

  wa_xml_table-hier = 2.
  wa_xml_table-type = 'V'.
  wa_xml_table-cname = 'allprop'.
  wa_xml_table-cvalue = ''.
  APPEND wa_xml_table TO xml_table.


* Create XML
  CALL FUNCTION 'SMUM_XML_CREATE'
    IMPORTING
      xml_output = xml_output
    TABLES
      xml_table  = xml_table.


******************************************************************
* Get Properties via HTTP 
******************************************************************

* Create HTTP_CLIENT object
  DATA: client TYPE REF TO if_http_client,
        timeout       TYPE i VALUE 0.

  CALL METHOD cl_http_client=>create_by_url
    EXPORTING
      url    = uri
    IMPORTING
      client = client.

* Authentication
  CALL METHOD client->authenticate
    EXPORTING
*    PROXY_AUTHENTICATION = ' '
*      CLIENT               = sy-mandt
      username             = user
      password             = pwd
*      LANGUAGE             = 'E'.


* Set Header Fields - methods PRPFIND
  CALL METHOD client->request->set_header_field
    EXPORTING
      name  = '~request_method'
      value = 'PROPFIND'.

  CALL METHOD client->request->set_header_field
    EXPORTING
      name  = '~server_protocol'
      value = 'HTTP/1.1'.

  CALL METHOD client->request->set_header_field
    EXPORTING
      name  = 'depth'
      value = '1'.

  CALL METHOD client->request->set_header_field
    EXPORTING
      name  = 'content-type'
      value = 'text/xml'.

  x_bytes = STRLEN( xml_output ).

  CALL METHOD client->request->set_cdata
    EXPORTING
      data   = xml_output
      length = x_bytes.

* send and receive with HTTP server 
  CALL METHOD client->send
    EXPORTING
      timeout                    = timeout
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 4.

  CASE sy-subrc.
    WHEN 1. RAISE http_communication_failure.
    WHEN 2. RAISE http_invalid_state.
    WHEN 3. RAISE http_processing_failed.
**    WHEN 4. RAISE others.
  ENDCASE.

  CALL METHOD client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 4.

  CASE sy-subrc.
    WHEN 1. RAISE http_communication_failure.
    WHEN 2. RAISE http_invalid_state.
    WHEN 3. RAISE http_processing_failed.
**    WHEN 4. RAISE others.
  ENDCASE.

* Get XML with properties
  DATA: xml_return TYPE string.
  xml_return = client->response->get_cdata( ).

* Get Global Status
  CALL METHOD client->response->get_status
    IMPORTING
      code   = code
      reason = reason.

* Close connection
  CALL METHOD client->close
    EXCEPTIONS
      http_invalid_state = 1
      OTHERS             = 2.


******************************************************************
* Parse Xml, Set Export table with properties
******************************************************************

  DATA: xml_doc TYPE xstring.
  DATA: xreturn TYPE bapiret2_t WITH HEADER LINE.


*  Convert XML to Xstring
  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      text           = xml_return
*   MIMETYPE       = ' '
*   ENCODING       =
   IMPORTING
     buffer         = xml_doc
   EXCEPTIONS
     failed         = 1
     OTHERS         = 2
            .
* Parse
  CALL FUNCTION 'SMUM_XML_PARSE'
    EXPORTING
      xml_input       = xml_doc
    TABLES
      xml_table       = tab_prop
      return          = xreturn
*    EXCEPTIONS
*      ERROR           = 1
            .

* Set Prop_Value, remove useless properties
  DATA: uc_prop_name TYPE string,
        uc_cname     TYPE string.

  uc_prop_name = prop_name.
  TRANSLATE uc_prop_name TO UPPER CASE.

  LOOP AT tab_prop INTO wa_xml_table.

    uc_cname = wa_xml_table-cname.
    TRANSLATE uc_cname TO UPPER CASE.

    IF uc_cname = uc_prop_name.
      prop_value =  wa_xml_table-cvalue.
    ENDIF.

    IF  wa_xml_table-type <> 'V'.
      DELETE tab_prop.
    ENDIF.

  ENDLOOP.

ENDFUNCTION.

Posted by ipercube


© 2026 Ipercube Design