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

Http Client

Former Member
0 Likes
557

hello i have created httpclient object in my prgram.

i sent request using httpclient, and source had life time set to session, and in my first request i set some page attributes.

now i am trying to use the same httpclient object in same program after first call to send request to same resource again assuming that httpclient now has all sesssion information that is required for web server to recognize a request for already created session but i cant get page attributes value that i expect because they are initial in second time,,so what should i do?

1 REPLY 1
Read only

Former Member
0 Likes
435

here is the code that might be helpful,,,,,

call method cl_http_client=>CREATE_BY_URL

EXPORTING

url = url

IMPORTING

client = httpClient.

httpClient->request->SET_HEADER_FIELD( name = '~request_uri'

value = uri ).

httpClient->request->SET_HEADER_FIELD( name = '~request_method'

value = 'POST' ).

httpClient->request->set_form_field( name = 'hello' value =

'World' ).

httpClient->request->set_form_field( name = 'mentor' value = 'daniel'

).

httpClient->send( httpClient->CO_TIMEOUT_INFINITE ).

call method httpClient->RECEIVE

EXCEPTIONS

HTTP_COMMUNICATION_FAILURE = 1

HTTP_INVALID_STATE = 2

HTTP_PROCESSING_FAILED = 3.

if sy-subrc = 0.

  • lastErrorMessage = 'Okay'.

  • lastErrorCode = 0.

  • errorCode = '-'.

data sTemp type string.

sTemp = httpClient->response->GET_CDATA( ).

create object printXMLDoc.

rc = printXMLDoc->parse_string( sTemp ).

call method printxmlDoc->display( ).

else.

call method httpClient->GET_LAST_ERROR

IMPORTING

code = lastErrorCode

message = lastErrorMessage.

write 😕 lastErrorMessage.

endif.

          • now here is another request using same object,,nd ******server resource is valid or active for session.

httpClient->request->SET_HEADER_FIELD( name = '~request_uri'

value = uri ).

httpClient->request->SET_HEADER_FIELD( name = '~request_method'

value = 'POST' ).

httpClient->request->set_form_field( name = 'hello' value =

'World' ).

httpClient->request->set_form_field( name = 'mentor' value = 'daniel Mcweeney'

).

        • the request below by this client shoud be *****recognized in same session

httpClient->send( httpClient->CO_TIMEOUT_INFINITE ).

call method httpClient->RECEIVE

EXCEPTIONS

HTTP_COMMUNICATION_FAILURE = 1

HTTP_INVALID_STATE = 2

HTTP_PROCESSING_FAILED = 3.

if sy-subrc = 0.

  • lastErrorMessage = 'Okay'.

  • lastErrorCode = 0.

  • errorCode = '-'.

sTemp = httpClient->response->GET_CDATA( ).

create object printXMLDoc.

rc = printXMLDoc->parse_string( sTemp ).

call method printxmlDoc->display( ).

*

*call function 'CALL_BROWSER'

*exporting

*url =

*'http://www.google.com'

    • WINDOW_NAME = ' '

    • BROWSER_TYPE =

    • CONTEXTSTRING =

*exceptions

*frontend_not_supported = 1

*frontend_error = 2

*prog_not_found = 3

*no_batch = 4

*unspecified_error = 5

*others = 6

*.

*if sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

*endif.

*

*CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE

*EXPORTING

*DOCUMENT = 'http://www.hotmail.com'.

else.

call method httpClient->GET_LAST_ERROR

IMPORTING

code = lastErrorCode

message = lastErrorMessage.

write 😕 lastErrorMessage.

endif.