Skip to Content

how to call http get api in abap

Dear All.

As I make new program interfacing with http API, 500 error code is occurring.

Calling API via IE is just like this

It's working well :

But in abap program, I got 500 error,

Would you please what's problem in my source ??

source code 1)

CALL METHOD cl_http_client=>create_by_destination
    destination           = 'MGAGE_BULK'
    client                = lo_client
    destination_not_found = 1
    internal_error        = 2.

request = lo_client->request.

CALL METHOD lo_client->request->set_method(
  if_http_request=>co_request_method_post ).

'<MESSAGE VER="1.2">'
'<USER USERNAME="*****"' 'PASSWORD="*****" DLR="0"/>'
'<SMS TEXT="This is first sms" ID="1" CUST_MID="customer-reference-uniqueid-20011234567890" MTAG="unique_message_tag_1">'
'<ADDRESS FROM="MGAGE" TO="+918826466" SEQ="1"/>'
'<SMS TEXT="This is second sms" ID="2" CUST_MID="customer-reference-uniqueid-20011234567891" MTAG="unique_message_tag_2">'
'<ADDRESS FROM="MGAGE" TO="+91882466" SEQ="1"/>'
INTO lv_bodystr.

name = 'data'.
value = lv_bodystr.
CALL METHOD request->set_form_field
    name  = name
    value = value.

CALL METHOD lo_client->send
    http_communication_failure = 1
    OTHERS                     = 4.

IF sy-subrc EQ 0.
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 4 ).

  lo_client->response->get_status( IMPORTING  code = lv_http_code
                                      reason = lv_reason ).

  lv_cdata = lo_client->response->get_cdata( ).

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Dec 27, 2017 at 10:19 AM

    Hi Kyoungmi,

    As you are attempting to consume an HTTPS service, you will first need to configure the security certificate in tcode STRUST (under SSL-client Anonymous). You can see and download the certificate by clicking on the lock icon next to the URL in Internet Explorer. Simply download and import it in your SAP system. Assuming that everything else is configured correctly, this should solved the issue.

    Additionally, check for a more detailed message in tcode SMICM.



    Add comment
    10|10000 characters needed characters exceeded

  • Dec 27, 2017 at 09:43 PM

    Isn't the HTTP error code 500 an "application error" (i.e. which occurs in the called system), so don't you get another message in the variable lv_cdata?

    As said by Tudor, use SMICM to trace the request sent + errors (eventually increase the trace level too).

    Maybe, you should call the following method, because you use special characters < and > which should be passed with values %3C and %3E (AKA "URL encoding"):

    Add comment
    10|10000 characters needed characters exceeded

    • Sandra Rossi Kyoungmi soyounglee929

      The code seems correct except what I said. I won't repeat. If it's unclear, please tell us what you don't understand.

      PS: 400 means (from Wikipedia + ) : "Bad Request. The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing)."

  • Dec 28, 2017 at 03:17 AM

    In sm59's result.

    This page can’t be displayed

    • Make sure the web address saphtmlp:// is correct.
    • Look for the page with your search engine.
    • Refresh the page in a few minutes.
    Add comment
    10|10000 characters needed characters exceeded

    • So, in fact your question is all about the configuration of SM59 RFC destination. Unfortunately you don't give any information about your config. You may also get some information in SMICM (Internet Communication Manager) HTTP trace, as we already said.