Skip to Content
avatar image
Former Member

Import URL data (http://requestb.in) into SAP using HTTP connection

Hi Experts,

I have requirement to get the response from External Gatewayapi which is built in PHP and JSON(http://requestb.in,which is like webhook).

Have created test webhook which stores the response from the Gateway at RAW BODY(see picture)

Now we have to import data into SAP. Have written sample code which gets data. Find the code and the data received.
call method cl_http_client=>create_by_url
 EXPORTING
 url = gV_URL
 IMPORTING
 client = http_client
 EXCEPTIONS
 others = 1.*system will use this Header Field to submit a Request to 3rd party’s API server
*after which we’ll receive the Response transmitted back to our Application Server.call method http_client->request->set_header_field
 EXPORTING
 name = '~request_method'
 value = 'GET'.*Structure of HTTP Connection and Dispatch of Data
call method http_client->send
 EXCEPTIONS
 http_communication_failure = 1
 http_invalid_state = 2.
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 DISPLAY LIKE SY-MSGTY.
 exit.
ENDIF.
* 5 - Get the result back
*get the Response back from the API servercall method http_client->receive
 EXCEPTIONS
 http_communication_failure = 1
 http_invalid_state = 2
 http_processing_failed = 3.
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 DISPLAY LIKE SY-MSGTY.
 exit.
ENDIF.
Data :lv_code type i,
 xml_string TYPE Xstring.
data:lv_reason type string.
data: xml_table type xml_line_structure occurs 0 with header line.
data: xreturn type bapiret2_t with header line.
*
http_client->response->get_status( IMPORTING code = lv_code reason = lv_reason ).
*
xml_string = http_client->response->get_data( ).
CALL FUNCTION 'SMUM_XML_PARSE'
 EXPORTING
 XML_INPUT = xml_string
 TABLES
 XML_TABLE = xml_table
 RETURN = xreturn

page_content = http_client->response->get_data( ).
CALL FUNCTION 'LXE_COMMON_XSTRING_TO_TABLE'
  EXPORTING
    IN_XSTRING = page_content
  IMPORTING
    PSTATUS    = lv_status
  TABLES
    EX_TAB     = LT_EX_TAB

Data Received in internal table

After converting data from AScii to Char

<!DOCTYPE html>#<html># <head># <title>RequestBin - ym1r3cym</title># <link rel="shortcut icon" href="data:image/gif;base64,R0lGODlhEAAQAIAAAKC0yAAAACH5BAQAAAAALAAAAAAQABAAAAIOhI+py+0Po5y02ouzPgUAOw==" /># <link href="/static/css/bootstrap.css"

Not sure what data is it.Need inputs to proceed further at earliest.

Any code snippets,approach or suggestion would be helpful.

requestbin.png (42.0 kB)
data.png (8.2 kB)
charformat.png (13.8 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers