cancel
Showing results for 
Search instead for 
Did you mean: 

change HTTP_GET in CLASS

Former Member
0 Kudos

Hi,

i use HTTP in this case:

DATA: BEGIN OF BODY_REQ OCCURS 0, LINE TYPE CHAR80, END OF BODY_REQ.

*

CALL FUNCTION 'HTTP_GET'

EXPORTING

ABSOLUTE_URI = 'http://www. ... '

RFC_DESTINATION = 'SAPHTTP' "s. Tabelle THTTP

BLANKSTOCRLF = 'Y'

TABLES

REQUEST_ENTITY_BODY = BODY_REQ.

*

LOOP AT BODY_RES.

WRITE: / BODY_RES.

ENDLOOP.

it works OK.

Now i will do the same in class and try this:

DATA: HTTP_CLIENT TYPE REF TO IF_HTTP_CLIENT .

*

DATA: 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.

*

WF_STRING = 'http://www. ... '.

*

CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL

EXPORTING

URL = WF_STRING

PROXY_HOST = 'nnn.nnn.nnn.nnn' " IP of SAPHTTP (Table THTTP).

PROXY_SERVICE = '8080'

IMPORTING

CLIENT = HTTP_CLIENT

EXCEPTIONS

ARGUMENT_NOT_FOUND = 1

PLUGIN_NOT_ACTIVE = 2

INTERNAL_ERROR = 3

OTHERS = 4.

*

CALL METHOD HTTP_CLIENT->SEND

EXCEPTIONS

HTTP_COMMUNICATION_FAILURE = 1

HTTP_INVALID_STATE = 2.

*

CALL METHOD HTTP_CLIENT->RECEIVE

EXCEPTIONS

HTTP_COMMUNICATION_FAILURE = 1

HTTP_INVALID_STATE = 2

HTTP_PROCESSING_FAILED = 3.

*

CLEAR RESULT .

RESULT = HTTP_CLIENT->RESPONSE->GET_CDATA( ).

*

REFRESH RESULT_TAB .

SPLIT RESULT AT CL_ABAP_CHAR_UTILITIES=>CR_LF INTO TABLE RESULT_TAB .

*

LOOP AT RESULT_TAB INTO R_STR.

WRITE:/ R_STR .

ENDLOOP .

But i get connection error.

Any idea, which error i do. Can i use RFC_DESTINATION for Proxy?

Thanks for help.

Regards,

Dieter

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

no idea??

Regards,

Dieter

Former Member
0 Kudos

Hi Dieter,

I just copied your example and it works fine for me.

I used our proxy (the host name) and proxy port, not a RFC destination.

No idea, I am sorry

regards

Tobias

athavanraja
Active Contributor
0 Kudos

in your working http_get model you dont use proxy, that means you dont connect internet via proxy server.

so dont pass proxy details to cl_http_client model as well

CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL

EXPORTING

URL = WF_STRING

IMPORTING

CLIENT = HTTP_CLIENT

EXCEPTIONS

ARGUMENT_NOT_FOUND = 1

PLUGIN_NOT_ACTIVE = 2

INTERNAL_ERROR = 3

OTHERS = 4.

Former Member
0 Kudos

Hi,

thanks for your answer, but i have the same problems,

I us a proxy-server witch is declared in THTTP.

Look at my FM-Call:

CALL FUNCTION 'HTTP_GET'

EXPORTING

ABSOLUTE_URI = 'http://www. ... '

RFC_DESTINATION = 'SAPHTTP' "s. Tabelle THTTP

BLANKSTOCRLF = 'Y'

TABLES

REQUEST_ENTITY_BODY = BODY_REQ.

Regards, Dieter

athavanraja
Active Contributor
0 Kudos

if you want to use proxy server / authentication with cl_http_client here is the code sample.


call method cl_http_client=>create
  exporting
    host          = 'www.webservicex.net'
    service       = '80'
    scheme        = '1'
    proxy_host    =  wf_proxy " here pass proxy server (proxy.domain.com)
    proxy_service =  wf_port " here pass proxy port (80)
  importing
    client        = http_client.

http_client->propertytype_logon_popup = http_client->co_disabled.

wf_user = user . " proxy server auth user id
wf_password = password . " proxy server auth pwd.

call method http_client->authenticate
  exporting
    proxy_authentication = 'X'
    username             = wf_user
    password             = wf_password.

athavanraja
Active Contributor
0 Kudos

alternatively, if you dont want to pass here and set the proxy details and authentication globally (for the whole system)

you can do it from

transaction SM59->RFC->HTTP Proxy configuration

Former Member
0 Kudos

Hi Durairaj,

perhaps ei made an errror in my first thread.

CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL

EXPORTING

URL = WF_STRING

PROXY_HOST = 'nnn.nnn.nnn.nnn' " IP of SAPHTTP (Table THTTP).

PROXY_SERVICE = '8080'

IMPORTING

CLIENT = HTTP_CLIENT

EXCEPTIONS

ARGUMENT_NOT_FOUND = 1

PLUGIN_NOT_ACTIVE = 2

INTERNAL_ERROR = 3

OTHERS = 4.

*

CALL METHOD HTTP_CLIENT->SEND

EXCEPTIONS

HTTP_COMMUNICATION_FAILURE = 1

HTTP_INVALID_STATE = 2.

*

CALL METHOD HTTP_CLIENT->RECEIVE

EXCEPTIONS

HTTP_COMMUNICATION_FAILURE = 1

HTTP_INVALID_STATE = 2

HTTP_PROCESSING_FAILED = 3.

*

Here i get the HTTP_COMMUNICATION_FAILURE error (sy-subrc = 1).

I use this as URL in first call:

WF_STRING = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'.

In CALL FUNCTION 'HTTP_GET' i get the result of this page in an internal table.

In CALL METHOD HTTP_CLIENT->RECEIVE i get an HTTP_COMMUNICATION_FAILURE, why??

Sorry, perhaps i have described by Problem in my first question wrong.

Regards, Dieter

Regards,

Dieter

athavanraja
Active Contributor
0 Kudos

if you enter this('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml') address in browser (e.g internet explorer)

and hit enter do you get a pop up asking for uid/pwd for proxy server.

if the answer is yes


call method cl_http_client=>create_by_url
    exporting
      url           = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'
      proxy_host    = wf_proxy " here pass proxy server (proxy.domain.com)
      proxy_service = wf_port " here pass proxy port (80)
    importing
      client        = http_client.

 
http_client->propertytype_logon_popup = http_client->co_disabled.
 
wf_user = user . " proxy server auth user id
wf_password = password . " proxy server auth pwd.
 
call method http_client->authenticate
  exporting
    proxy_authentication = 'X'
    username             = wf_user
    password             = wf_password.
  http_client->send( ).
  http_client->receive( ).

  clear result_xml .
  result_xml = http_client->response->get_cdata( ).
  http_client->close( ).

if the answer is no


call method cl_http_client=>create_by_url
    exporting
      url           = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'
    importing
      client        = http_client.

  http_client->send( ).
  http_client->receive( ).

  clear result_xml .
  result_xml = http_client->response->get_cdata( ).
  http_client->close( ).

in your earlier case you may getting the http communication error becuase of missing proxy authentication.

let me know how it goes.

Regards

Raja

Answers (1)

Answers (1)

Former Member
0 Kudos

I have exactly the same problem. I am actually getting an XML file back that says something about

404 Resource not found. Partner not reached.

If I do the HTTP_GET function everything works fine, but I am having problems with the HTTP_POST function, so I wanted to switch to using the IF_HTTP_CLIENT class, but I just can't get it to work. My code:

FORM post_xml using url xml_xstring_in

changing xml_xstring_out.

data: client type ref to if_http_client,

xml_string type string,

xml_response type ref to cl_xml_document.

cl_http_client=>create_by_url( exporting url = url importing client = client exceptions others = 1 ).

client->request->set_header_field( exporting name = '~request_method' value = 'POST' ).

client->request->set_header_field( exporting name = '~server_protocol' value = 'HTTP/1.1' ).

client->request->set_header_field( exporting name = 'Content-Type' value = 'text/xml' ).

client->request->set_data( exporting data = xml_xstring_in offset = 0 ).

client->send( exceptions http_communication_failure = 1 http_invalid_state = 2 ).

client->receive( exceptions http_communication_failure = 1 http_invalid_state = 2 http_processing_failed = 3 ).

xml_xstring_out = client->response->get_data( ).

client->close( ).