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

How to read data from URL <https://xyz.php> into a string or internal table

rishabh_pandey2
Explorer
0 Likes
14,320

Hello,

I have a requirement to read data from given URL by 3rd Party e-commerce portal.

I have already use  If_http_client,   cl_http_client=>create_by_url, but unable to read data.

Can anyone help me regarding this issue.

Regards,

Rishabh.

25 REPLIES 25
Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
0 Likes
13,267

How did you tried to read data?

What it means "unable to read data" ? Any exceptions, errors?


-- Tomas --
Read only

0 Likes
13,267

Hello Tomas,

Here is my Code,

DATA: l_http_client TYPE REF TO if_http_client.

DATA: lv_string TYPE xstring,

       lv_content TYPE xstring,

       lv_i TYPE i,

       lv_url TYPE string VALUE 'https://abcdxyz.php'

CALL METHOD cl_http_client=>create_by_url

   EXPORTING

     url                = lv_url

   IMPORTING

     client             = l_http_client

   EXCEPTIONS

     argument_not_found = 1

     plugin_not_active  = 2

     internal_error     = 3.


CHECK sy-subrc = 0.

l_http_client->propertytype_logon_popup = l_http_client->co_disabled.

l_http_client->request->set_header_field( EXPORTING name  = '~request_method'

                                                      value = 'GET' ).

*

l_http_client->request->set_header_field( EXPORTING name  = '~server_protocol'

                                                      value = 'HTTP/1.0' ).


CALL METHOD l_http_client->send

   EXCEPTIONS

     http_communication_failure = 1

     http_invalid_state         = 2.

CHECK sy-subrc = 0.

CALL METHOD l_http_client->receive

   EXCEPTIONS

     http_communication_failure = 1

     http_invalid_state         = 2

     http_processing_failed     = 3.

CHECK sy-subrc = 0.

l_http_client->response->get_status( IMPORTING code = lv_i ).


lv_string = l_http_client->response->get_data( ).

lv_content = lv_string.

Please Suggest.

Regards,
Rishabh

Read only

0 Likes
13,267

Hi,

I have here a post that use CL_HTTP_CLIENT .

Please try the code .

Also make sure that SAP have access to the Internet (you might need to use the proxy parameter).

                  

Regards.

Read only

matt
Active Contributor
0 Likes
13,267

Love it. You ask


Tomas Buryanek wrote:

How did you tried to read data?

What it means "unable to read data" ? Any exceptions, errors?


and the OP responds with the code. But nothing about exceptions or errors.

Read only

sabirshah1
Participant
0 Likes
13,267

Hi,

Try This .

call method cl_http_client=>create_by_url

    exporting

      url           = 'httyp://abc.com/abc.xml'

    importing

      client        = http_client.

  http_client->send( ).

  http_client->receive( ).

clear xml_out .

  xml_out = http_client->response->get_cdata( ).

  http_client->close( ).

Use FM SMUM_XML_PARSE to convert  xml_out to internal table

Regards,

Sabir

Read only

0 Likes
13,267

Hi Sabir,

Thanks for your reply.

I have a URL which extension is .php  so i have to read data from that only.

when i click on my URL then i got a numbers of records with ',' delimiter on browser.

regards,

Rishabh

Read only

RaymondGiuseppi
Active Contributor
0 Likes
13,267

You have (at least) to call in sequence some method, e.g.

  • cl_http_client=>create or create_by_url
  • if_http_client->send
  • if_http_client->receive
  • if_http_client->response->get_cdata( ).

Which error did you get, what did you already try?

Regards,

Raymond

Read only

0 Likes
13,267

Hi raymond,

I am getting 404 Not found Error.

Regards,

Rishabh.

Read only

0 Likes
13,267
Read only

0 Likes
13,267

Hi Rishabh,

did you try to copy and paste the link into your browser on the application server?

The 404 error simply means that the file specified by the link does not exist and maybe your frontend can access the internet, but not the backend.

Best regards,

Dominik

Read only

0 Likes
13,267

Hi Eitan,

I have tried your code also but your code is based on XML and my URL is .PHP.

so in my case it is not working.

Regards,

Rishabh

Read only

0 Likes
13,267

Hi Dominik,

Yes i have tried into browser and there i am getting data like notepad(.txt) format.

Best Regards

Rishabh.

Read only

0 Likes
13,267

Hi,

True.

My idea was to check if you can get something of the web.

Did the code work for you as is ?

Change the url to your url and put a break point here :

What is the content of field "response_string_1"  ?

You wrote "i got a numbers of records with ',' delimiter on browser."

You need to write a code to parse those records.

Do a google using search operatorssite:scn.sap.com  parse csv file

                  

Regards.

Read only

0 Likes
13,267

Hi Eitan,

I have tried your code as it is & URL also but i am getting SY-SUBRC = 1 after CALL METHOD client->receive.

Regards,

Rishabh.

Read only

0 Likes
13,267

Hi,

Looks like you have communication problem to the web.

This what I get:

Replace CONSTANTS: c_url TYPE string VALUE 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml' .

with some intranet link  (https://en.wikipedia.org/wiki/Intranet)

Read only

0 Likes
13,261

Hi Eitan,

Sorry for Bother you but i am not getting what is the problem.

Regards,

Rishabh

Read only

0 Likes
13,261

Hi,

1 means http_communication_failure

please replace CONSTANTS: c_url TYPE string VALUE 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml' .

with some intranet link  (https://en.wikipedia.org/wiki/Intranet) .

also talk with you basis team about the problem.

Regards.

Read only

0 Likes
13,261

Hi Eitan,

Thanks for your quick reply ,

we added host file to the server but still we are facing same problem

also replaced URL with local Intranet URL.

Best Regards,
Rishabh

Read only

0 Likes
13,261

Check if there is system message and what it says:


IF sy-subrc <> 0.

     MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno

           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Also this can get more info (probably same as in system message though):


cl_http_client=>get_last_error(

      IMPORTING

        code    = code    " Error Code

        message = message    " Error Message

).

But what Eitan already wrote. It looks like problem to solve for basis team.

-- Tomas --
Read only

0 Likes
13,261

Any Firewall ?

Any Proxy that can be used ?

Authority ?

Ask the basis to login to the application server and see if he can access the web from there.

Regards.

Read only

0 Likes
13,261

Hi Eitan,

I can´t find any proxy settings in my system, I looked into SICF->client->proxy settings, and everything is blank. Where should I see the setting you refer to? Should be there?

I´ll keep the research with the clue you gave to me, but I´ll be grateful if you could help me just a bit more.

Regards,

Rishabh.

Read only

0 Likes
13,261

Hi,

I am referring to proxy that might be in use in your network to get out to the web .

In my case it is the same proxy define in IE

Read only

0 Likes
13,261

Hi Eitan,

Which Servers are you running on and what is the OS, We are running on AIX and the problem is with the website since it keeps on changing the IP address.

Due to frequent change in IP address the servers are not able to resolve the web address.

Best Regards,

Rishabh.

Read only

0 Likes
13,261

Hi Tomas,

I am getting "Object <Program Name> of class RE and language EN does not exist"

error.

Regards,

Rishabh.

Read only

0 Likes
13,261

Hi,

It is a windows network .

The server is window server 2003 .

Regards.