Application Development 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: 

how to execute a URL ping in ABAP

Former Member
0 Kudos

Hi all,

i want to execute a URL ping from a ABAP function module but without any browser openning. I just want to check if the URL is correct and if it return true.

How can i do that ?

Regards,

Eric.

11 REPLIES 11

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

What release are you on? There is some nice HTTP client functionality in WebAS 610 and higher. I can supply a sample if the release level is correct.

0 Kudos

I'm using the WAS 6.20

But idon't want to open a browser and see the result of the URL ! i just want to know if the URL exist or not and / or if the server response is ok.

Eric.

0 Kudos

You misunderstand. The HTTP client is the SAP server itself. ABAP is the language the client is written in. Nothing will show in a browser. The functionaly allows you to open a HTTP connection, make a request and receive a response. The response data and return code is brought back directly to the calling abap program. This is all part of the native HTTP stack (ICM - Internet Connection Manager) in the WebAS. For this to work you don't even need a connection to a frontend (it can work in batch).

0 Kudos

No no i don't misunderstand anything !!

i understand what you write and it's exactly what i think about !!

So please have you got a simple example ABAP code to test this functionality ?

0 Kudos

Yes here is the sample:


 data:  client    type ref to if_http_client,
         url       type string.


****Build the Sending URL
  concatenate
    page_srv-send_url
    `&Message=`
    message
    `&Class=`
    class
    `&Number=`
    sms_number
    `&Priority=`
    priority
    `&Project=`
    page_srv-project_name
    `&Sendingnumber=`
    page_srv-sending_number
    into url.

****Create the HTTP client
  call method cl_http_client=>create_by_url
    exporting
      url    = url
      ssl_id = page_srv-ssl_id
    importing
      client = client
    exceptions
      others = 1.

****Set the Request type to GET
  client->request->set_header_field( name  = '~request_method'
                             value = 'GET' ).               "#EC *

****Make the call
  client->send( ).

****Receive the Response Object
  call method client->receive
    exceptions
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      others                     = 4.

****Get the response content in Character format
  p_content = client->response->get_cdata( ).

There is also a client->response->get_status( ) that you might find interesting. Check out the class definition to see the full range of options.

0 Kudos

Please note that from this example, you can leave off the SSL_ID from the CL_HTTP_CLIENT=>CREATE_BY_URL. This is just because I am calling a HTTPS site and I need to identify the client certificate.

0 Kudos

sorry but i don't understand the value "page_srv-ssl_id" i have to put in the method call "cl_http_client=>create_by_url".

0 Kudos

You can ignore this. I had to use it because I was calling an HTTPS site. This field had a link to my client certificate. Not necessary if you are calling to HTTP. In case you are interested in the details of calling HTTPS the following weblog should help:

/people/thomas.jung3/blog/2004/11/17/bsp-a-developers-journal-part-xiv--consuming-webservices-with-abap

0 Kudos

Thank very much Thomas, i will make a test.

See you !!

Eric.

former_member534411
Participant
0 Kudos

Eric Gourdou:

you have to implement javascript.

<html>

<head>

<title>welcome</title>

<script>function loadurl(url){window.open(url , "_self") }</script></head>

<body onload="javascript:loadurl('URL')">Loading . . . . . </body>

</html>

please save above code as html and speicify your url name instead of URL text.

then move to transaction SMW0 select HTML templates option for WebRFC application and then execute from the next screen. click create and give a object name, description then import the HTML file you have saved.

and use this function module in your ABAP code

call method html_control->load_html_document

Regards

Suresh Babu Karanam

0 Kudos

Dear Suresh,

i don't understand what you mean by:

and use this function module in your ABAP code

call method html_control->load_html_document

how can i use my object created in the SMW0 transaction in a function module ?

could you please give me an eample !!

Eric.