<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Adding a cookie to an http request in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/adding-a-cookie-to-an-http-request/m-p/609086#M25079</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;My problem is now solved. It turns out the cookie name has the character "." and SAP is encoding/replacing the "." character by "%2e". As a result the server is not understanding the cookie name.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;To avoid the encoding, just apply SAP NOTE 1160362 to set the parameter "ict/disable_cookie_urlencoding=1".&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Regards,&lt;/P&gt;</description>
    <pubDate>Tue, 17 Apr 2018 07:27:56 GMT</pubDate>
    <dc:creator>danielgonzalez</dc:creator>
    <dc:date>2018-04-17T07:27:56Z</dc:date>
    <item>
      <title>Adding a cookie to an http request</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/adding-a-cookie-to-an-http-request/m-p/609081#M25074</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt; I need to do a http request adding a specific cookie. It's working fine except the cookie part. It seems the cookie is not being sent according to the responde I'm getting from the server.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;This is the piece of code to create the http client:&lt;/P&gt;
  &lt;P&gt;CALL METHOD cl_http_client=&amp;gt;create_by_url EXPORTING&lt;BR /&gt; url ='url' &lt;/P&gt;
  &lt;P&gt;IMPORTING client = http_client&lt;/P&gt;
  &lt;P&gt;EXCEPTIONS&lt;BR /&gt; argument_not_found = 1&lt;BR /&gt; plugin_not_active = 2&lt;BR /&gt; internal_error = 3OTHERS = 4.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;I have used several pieces of code to add the cookie but unfortunately no success:&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;http_client-&amp;gt;request-&amp;gt;set_cookie( name = 'JSESSIONID'&lt;/P&gt;
  &lt;P&gt;value = l_session_id ).&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt; CALL METHOD http_client-&amp;gt;request-&amp;gt;set_cookie EXPORTING&lt;BR /&gt; name = 'JSESSIONID' value = &lt;/P&gt;
  &lt;P&gt;l_session_id.&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt; &lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;DATA: l_cookie_value TYPE string.&lt;/P&gt;
  &lt;P&gt;CONCATENATE 'JSESSIONID=' l_session_id INTO&lt;BR /&gt; l_cookie_value.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;CALL METHOD http_client-&amp;gt;request-&amp;gt;set_header_field EXPORTING&lt;BR /&gt; name = 'Cookie' value = l_cookie_value.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Any ideas what's wrong with my code?&lt;/P&gt;
  &lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 12:15:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/adding-a-cookie-to-an-http-request/m-p/609081#M25074</guid>
      <dc:creator>danielgonzalez</dc:creator>
      <dc:date>2018-04-13T12:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a cookie to an http request</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/adding-a-cookie-to-an-http-request/m-p/609082#M25075</link>
      <description>&lt;P&gt;I assume you are making an API call for something like POST/PATCH. If this is the case then first you will need to fetch XSRF token along with it you will get the cookie, use the object to make further POST/PATCH calls Please find below sample code taken from &lt;A href="https://api.sap.com/shell/discover/contentpackage/SAPCPWorkflowAPIs/api/SAP_CP_Workflow"&gt;API Hub&lt;/A&gt; for a PATCH Request&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;DATA: lo_http_client TYPE REF TO if_http_client.
DATA: response TYPE string.


"create HTTP client by url
"API endpoint for API sandbox 
CALL METHOD cl_http_client=&amp;gt;create_by_url
  EXPORTING
    url                = 'https://sandbox.api.sap.com/workflow-service/rest/v1/task-instances/{taskInstanceId}'


  IMPORTING
    client             = lo_http_client
  EXCEPTIONS
    argument_not_found = 1
    plugin_not_active  = 2
    internal_error     = 3
    OTHERS             = 4.


"Available API Endpoints
"https://bpmworkflowruntime{provideraccountname}-{consumeraccountname}.ap1.hana.ondemand.com/workflow-service/rest
"https://bpmworkflowruntime{provideraccountname}-{consumeraccountname}.br1.hana.ondemand.com/workflow-service/rest
"https://bpmworkflowruntime{provideraccountname}-{consumeraccountname}.ca1.hana.ondemand.com/workflow-service/rest
"https://bpmworkflowruntime{provideraccountname}-{consumeraccountname}.cn1.hana.ondemand.com/workflow-service/rest
"https://bpmworkflowruntime{provideraccountname}-{consumeraccountname}.eu3.hana.ondemand.com/workflow-service/rest
"https://bpmworkflowruntime{provideraccountname}-{consumeraccountname}.hana.ondemand.com/workflow-service/rest
"https://bpmworkflowruntime{provideraccountname}-{consumeraccountname}.hanatrial.ondemand.com/workflow-service/rest
"https://bpmworkflowruntime{provideraccountname}-{consumeraccountname}.jp1.hana.ondemand.com/workflow-service/rest
"https://bpmworkflowruntime{provideraccountname}-{consumeraccountname}.ru1.hana.ondemand.com/workflow-service/rest
"https://bpmworkflowruntime{provideraccountname}-{consumeraccountname}.us1.hana.ondemand.com/workflow-service/rest
"https://bpmworkflowruntime{provideraccountname}-{consumeraccountname}.us2.hana.ondemand.com/workflow-service/rest
"https://bpmworkflowruntime{provideraccountname}-{consumeraccountname}.us3.hana.ondemand.com/workflow-service/rest


IF sy-subrc &amp;lt;&amp;gt; 0.
  "error handling
ENDIF.


"setting request method
lo_http_client-&amp;gt;request-&amp;gt;set_method('PATCH').


"adding headers
lo_http_client-&amp;gt;request-&amp;gt;set_header_field( name = 'X-CSRF-Token' value = 'string' ).
lo_http_client-&amp;gt;request-&amp;gt;set_header_field( name = 'Content-Type' value = 'application/json' ).
lo_http_client-&amp;gt;request-&amp;gt;set_header_field( name = 'Accept' value = 'application/json' ).
"API Key for API Sandbox
lo_http_client-&amp;gt;request-&amp;gt;set_header_field( name = 'APIKey' value = '&amp;lt;API_KEY&amp;gt;' ).




"Available Security Schemes for productive API Endpoints
"Basic Authentication, OAuth 2.0


"Basic Auth : provide username:password in Base64 encoded in Authorization header
"lo_http_client-&amp;gt;request-&amp;gt;set_header_field( name = 'Authorization' value = 'Basic &amp;lt;Base64 encoded value&amp;gt;' ).


CALL METHOD lo_http_client-&amp;gt;request-&amp;gt;set_cdata
  EXPORTING
    data = '{  "context": {},  "status": "COMPLETED",  "subject": "string",  "description": "string",  "recipientUsers": "string",  "recipientGroups": "string",  "processor": "string",  "dueDate": "2018-04-13T12:22:35.793Z",  "priority": "VERY_HIGH"}'.


CALL METHOD lo_http_client-&amp;gt;send
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2
    http_processing_failed     = 3
    http_invalid_timeout       = 4
    OTHERS                     = 5.


IF sy-subrc = 0.
  CALL METHOD lo_http_client-&amp;gt;receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 5.
ENDIF.


IF sy-subrc &amp;lt;&amp;gt; 0.
  "error handling
ENDIF.


response = lo_http_client-&amp;gt;response-&amp;gt;get_cdata( ).


WRITE: 'response: ', response.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Apr 2018 12:25:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/adding-a-cookie-to-an-http-request/m-p/609082#M25075</guid>
      <dc:creator>nabheetscn</dc:creator>
      <dc:date>2018-04-13T12:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a cookie to an http request</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/adding-a-cookie-to-an-http-request/m-p/609083#M25076</link>
      <description>&lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Thanks &lt;A href="https://answers.sap.com/users/46449/nabheetmadan3.html"&gt;Nabheet Madan&lt;/A&gt; but I'm executing a POST method in fact it's a soap web service for which we're having problems to do it the clean way by using abap proxies that's why we resorted to do a htttp call.&lt;/P&gt;
  &lt;P&gt;Any ideas what it's wrong with my code?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 12:36:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/adding-a-cookie-to-an-http-request/m-p/609083#M25076</guid>
      <dc:creator>danielgonzalez</dc:creator>
      <dc:date>2018-04-13T12:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a cookie to an http request</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/adding-a-cookie-to-an-http-request/m-p/609084#M25077</link>
      <description>&lt;P&gt;Just before executing the http request I have cheched the cookie is correctly set with this piece of code:&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;DATA: l_t_cookies TYPE tihttpcki,&lt;BR /&gt; l_wa_cookie TYPE line of tihttpcki.&lt;/P&gt;
  &lt;P&gt;CALL METHOD lo_http_client-&amp;gt;request-&amp;gt;get_cookies CHANGING &lt;/P&gt;
  &lt;P&gt;cookies = l_t_cookies.&lt;/P&gt; LOOP AT l_t_cookies INTO l_wa_cookie.
  &lt;P&gt;WRITE:/ sy-tabix, l_wa_cookie-name, l_wa_cookie-value.&lt;/P&gt;
  &lt;P&gt;ENDLOOP.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Any ideas why it seems the cookie is not getting the server.&lt;/P&gt;
  &lt;P&gt;Regards,&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 13:34:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/adding-a-cookie-to-an-http-request/m-p/609084#M25077</guid>
      <dc:creator>danielgonzalez</dc:creator>
      <dc:date>2018-04-13T13:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a cookie to an http request</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/adding-a-cookie-to-an-http-request/m-p/609085#M25078</link>
      <description>&lt;P&gt;Please paste your complete code where you get the cookie and then you pass back&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 13:58:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/adding-a-cookie-to-an-http-request/m-p/609085#M25078</guid>
      <dc:creator>nabheetscn</dc:creator>
      <dc:date>2018-04-13T13:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a cookie to an http request</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/adding-a-cookie-to-an-http-request/m-p/609086#M25079</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;My problem is now solved. It turns out the cookie name has the character "." and SAP is encoding/replacing the "." character by "%2e". As a result the server is not understanding the cookie name.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;To avoid the encoding, just apply SAP NOTE 1160362 to set the parameter "ict/disable_cookie_urlencoding=1".&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Tue, 17 Apr 2018 07:27:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/adding-a-cookie-to-an-http-request/m-p/609086#M25079</guid>
      <dc:creator>danielgonzalez</dc:creator>
      <dc:date>2018-04-17T07:27:56Z</dc:date>
    </item>
  </channel>
</rss>

