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 do I get a cookie from a HTTP Post using the HTTP_CLIENT class

Former Member
0 Likes
4,782

Hi,

Can anyone provide me some sample code of how to successfully get a list of cookies from a HTTP POST and send a list of cookies to an HTTP get. My code below does not seem to work. I know the URL I am posting to returns some cookies and the subsequent HTTP GET requires these cookies. I really don't need to know the names or the values of the cookies, I just need to be able to send them via the HTTP GET:

  • Code Example

data: client type ref to if_http_client,

xml_string type string,

xml_response type ref to cl_xml_document,

zsubrc type sy-subrc.

data: cookies type TIHTTPCKI.

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

CLIENT->PROPERTYTYPE_ACCEPT_COOKIE = 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->request->RECEIVE_COOKIE.

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

client->request->GET_COOKIES( changing cookies = cookies ).

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

client->close( ).

Hi,

Can anyone provide me some sample code of how to successfully get a list of cookies from a HTTP POST and send a list of cookies to an HTTP get. My code below does not seem to work. I know the URL I am posting to returns some cookies and the subsequent HTTP GET requires these cookies. I really don't need to know the names or the values of the cookies, I just need to be able to send them via the HTTP GET:

  • Code Example

data: client type ref to if_http_client,

xml_string type string,

xml_response type ref to cl_xml_document,

zsubrc type sy-subrc.

data: cookies type TIHTTPCKI.

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

CLIENT->PROPERTYTYPE_ACCEPT_COOKIE = 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->request->RECEIVE_COOKIE.

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

client->request->GET_COOKIES( changing cookies = cookies ).

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

client->close( ).

1 REPLY 1
Read only

Former Member
0 Likes
3,813

Hi Peter,

have you found an example? I'm trying to do the same, but have not found anything useful.

Thanks!