Skip to Content
Author's profile photo Former Member

Set and Get custom HTTP Header

This blog is to illustrate following solution which might be helpful in certain scenario:

     1. Set Custom HTTP Header in sapui5

     2. Get Custom HTTP Header in Gateway

So Let’s start !

1. How to set custom HTTP Header in sapui5


This is simple and can be achieved by setHeaders method of either sap.ui.model.odata.v2.ODataModel or sap.ui.model.odata.ODataModel.

Code snippet:

UI5 Code.JPG

Able to see customer header sets in F12:

     F12 in Chrome.JPG

2. How to get custom HTTP Header in GW


Also simple by calling get_dp_facade of interface /iwbep/if_mgw_conv_srv_runtime.

Code snippet:

     GW Code Snipet.JPG

Able to see in GW code runtime:

     Header in GW.JPG

Now we able to set HTTP custom header in UI5 and get in GW.

This is sometimes helpful when you want to pass additional data from UI to GW but found nowhere to place them.

e.g. When implement get_entity/get_stream method, few places we can put parameters. Then maybe header is a place to consider.

Hope it helps !

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Vamsi Krishna C V
      Vamsi Krishna C V

      Thank You Very Much for this Yis. You just saved me a lot of development time! 🙂

      Author's profile photo Former Member
      Former Member

      Hi Sun,

      Thanks for the blog, can you please inform how to remove the headers as well?

      Thanks in advance.

      Regards,

      Anand T

      Author's profile photo Danny Van der Steen
      Danny Van der Steen

      Thanks,

       

      needed this helped me a lot.

       

      Greetings,

       

      Danny

      Author's profile photo Rajdeep BHUVA
      Rajdeep BHUVA

      Hi,

       

      When i add params via fileuploader class, i couldn't get it in create_stream method.

       

      Do you have any solution?

       

      Thanks,

      Rajdeep

      Author's profile photo Zayidu Ansari
      Zayidu Ansari

      Thanks for this!