Skip to Content
avatar image
-1
Former Member

how to encoding special character which is in get parameter of http API

api-1.jpg

api-2.jpg

Dear.

I'm struggling to implement attach API to ABAP as POST method.

But, API returns 500 error code when calling API.

Would you check what's problem on my source code ?

     CALL METHOD cl_http_client=>create

        EXPORTING

          host    = 'mgage.solutions'

          service = '80'

          scheme  = '1'

        IMPORTING

          client  = lo_client.



      CALL METHOD lo_client->request->set_header_field

        EXPORTING

          name  = '~request_uri'

          value = 'http://www.mgage.solutions/servxml/XML_parse_API.php'.



      IF sy-subrc <> 0.

        MESSAGE e000(cuan_mkt_exec_frw) INTO ev_message WITH 'MGAGE'.

        RETURN.

      ENDIF.



      request = lo_client->request.



      CALL METHOD request->set_header_field

        EXPORTING

          name  = 'content-type'

          value = 'text/html; charset=UTF-8'.





      CALL METHOD request->set_header_field

        EXPORTING

          name  = '~request_method'

          value = 'POST'.





      CONCATENATE

        '<MESSAGE VER="1.2">'

        '<USER USERNAME="' ls_config-char20  '" PASSWORD="' ls_config-char20a '" DLR="0"/>'

      INTO lv_bodystr.



      lv_seq = 0.


      LOOP AT gt_smt_tran INTO gs_smt_tran.

        CLEAR lv_result.

        CLEAR name.

        CLEAR value.



        lv_seq = lv_seq + 1.

        lv_seq_c = lv_seq.


        REPLACE ALL OCCURRENCES OF '+'  IN  gs_smt_tran-recipient_num WITH '' .


       CONCATENATE

         lv_bodystr

         '<SMS TEXT="'  lv_query      '" ID="' lv_seq_c

         '" CUST_MID="' gs_smt_tran-recipient_num'-'      gs_smt_tran-camp_id

         '" MTAG="'     gs_smt_tran-camp_id      '">'

         '<ADDRESS FROM="SAMSNG" TO="' gs_smt_tran-recipient_num '" SEQ="1"/>'

         '</SMS>'

        INTO lv_bodystr.



      ENDLOOP.



      CONCATENATE

        lv_bodystr '</MESSAGE>'

      INTO lv_bodystr.



      lo_client->propertytype_logon_popup = lo_client->co_disabled.



      lo_conv_utf8  = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' ).

      lo_conv_utf8->write( data =  lv_bodystr ).

      lv_butf8 = lo_conv_utf8->get_buffer( ).



      CALL METHOD request->set_data

        EXPORTING

          data = lv_butf8.





      CALL METHOD lo_client->send

        EXCEPTIONS

          http_communication_failure = 1

          http_invalid_state         = 2

          http_processing_failed     = 3

          http_invalid_timeout       = 4

          OTHERS                     = 5.


      IF sy-subrc EQ 0.

        lo_client->receive(

          EXCEPTIONS

            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_http_code is 500 code when calling API

So need to get help sincerely how to call API as post method.

Regards,

SJ.

api-1.jpg (438.7 kB)
api-2.jpg (392.9 kB)
Add comment
10|10000 characters needed characters exceeded

  • How do you know the error 500 is related to a character encoding issue?

    PS: in your code, the UTF-8 encoding part is okay, but the XML building does not take into account that the variable part may contain characters ", < and &. You should replace them with & quot; & lt; and & amp; (no space after & )


  • Get RSS Feed

0 Answers