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

Sending SMS from coding

Former Member
0 Likes
661

Dear SDNers,

I worte the below code to send an sms.


REPORT  zsend_sms.
DATA: W_http_client TYPE REF TO if_http_client .
DATA: wf_string TYPE string ,
      result TYPE string ,
      r_str TYPE string .
DATA: result_tab TYPE TABLE OF string.

SELECTION-SCREEN: BEGIN OF BLOCK a WITH FRAME .
PARAMETERS: mail(100) LOWER CASE,
            m_no(20) LOWER CASE ,
            m_mss(120) LOWER CASE.
SELECTION-SCREEN: END OF BLOCK a .

START-OF-SELECTION .

  CLEAR wf_string .
  CONCATENATE  'http://102.175.33.18:4567/pushurl/?user=abapuser&pwd=abap123&src=045670&dest='m_no'&msg='m_mss
 INTO wf_string .

  CALL METHOD cl_http_client=>create_by_url
    EXPORTING
      url                = wf_string
    IMPORTING
      client             = W_http_client
    EXCEPTIONS
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      OTHERS             = 4.
******************************************************************
DATA: EMPTYBUFFER TYPE XSTRING.

      EMPTYBUFFER = ''.
  CALL METHOD W_HTTP_CLIENT->REQUEST->SET_DATA
        EXPORTING DATA = EMPTYBUFFER.


CALL METHOD W_HTTP_CLIENT->AUTHENTICATE
  EXPORTING
    USERNAME             = 'abapuser'
    PASSWORD             = 'abap123'.
    "LANGUAGE             = SY-LANGU

CALL METHOD W_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
     EXPORTING NAME  = '~request_method'
               VALUE = 'GET'
                .

 CALL METHOD W_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
      EXPORTING NAME  = 'Content-Type'
                VALUE = 'text/xml; charset=utf-8'.

 CALL METHOD W_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
      EXPORTING NAME  = 'Accept'
                VALUE = 'text/xml, text/html'.
data:SOAP_ACTION TYPE STRING.
 CONCATENATE wf_string '#' INTO SOAP_ACTION.
 CALL METHOD W_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
      EXPORTING NAME  = 'SOAPAction'
                VALUE = SOAP_ACTION.

************************************************************************
  CALL METHOD W_http_client->send
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2.

  CALL METHOD W_http_client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3.


****************************************************************************
DATA: HTTP_STATUS_CODE TYPE I,
      STATUS_TEXT TYPE STRING.
CALL METHOD W_HTTP_CLIENT->RESPONSE->GET_STATUS
    IMPORTING
      CODE = HTTP_STATUS_CODE
      REASON = STATUS_TEXT
      .
  WRITE: / 'HTTP_STATUS_CODE = ',
          HTTP_STATUS_CODE,
         / 'STATUS_TEXT = ',
         STATUS_TEXT
         .
DATA:W_RESULT TYPE STRING.
"STEP-6 :  READ RESPONSE DATA
 CALL METHOD W_HTTP_CLIENT->RESPONSE->GET_CDATA
        RECEIVING DATA = W_RESULT .

****************************************************************************

I am getting below response.

HTTP_STATUS_CODE = 404

STATUS_TEXT = conn failed

But If i use the above url in a browser, I m succeeded. Only from SAP its not working. Kindly put some light on this.

Thanks,

Venkat

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
613

Hi

<Link removed by moderator>

Thanks & regards,

Edited by: Vinod Kumar on Nov 30, 2011 12:17 PM

4 REPLIES 4
Read only

Former Member
0 Likes
614

Hi

<Link removed by moderator>

Thanks & regards,

Edited by: Vinod Kumar on Nov 30, 2011 12:17 PM

Read only

0 Likes
613

Can anybody update me on the above issue.

Regards,

Venkat

Read only

0 Likes
613

Hi Venket,

error HTTP CODES 404 is occur because it is not getting the file which you want to send as SMS.

HTTP CODES 404-The document/file requested by the client was not found.

also you can try to catch the exception and then see what is the problem behind it.

i think it will work.

Thanks,

Khush

Read only

0 Likes
613

Dear Khush,

Here is the error.

Application Server Error

404 Resource Not Found

Partner not Reached

But if I try the same url with broswer,its working fine.

Regaards,

Venkat

Thanks to everyone, after opeining the ports, the above code is working fine for me. I m closing this thread.