How to set big cookie header in karate

时光怂恿深爱的人放手 提交于 2021-01-27 21:51:50

问题


As part of our automation we need to send very huge cookie header to the api.

cookie is as below cookie: _ga=GA1.2.1041556506.1557744563; _gcl_au=1.1.139136457.1560512273; JabmoSP0id.ffef=d37c42bf-f223-43c6-a73c-fa502e23712d.1560512274.5.1561197329.1560589232.2561e1f4-79fe-4b63-88c6-157c6e8ed125; _gid=GA1.2.1289186220.1561356841; intercom-session-pk0ds0sg=TlZDS2xJQ3BjdldKQ3QzVkt2U1VkUUJ0WmhsVDBpaTY0YThBR0M0Y0dFMWs1azkwUlBlTWpUbWp1ZHN6MUtydS0tZm5CSlZYU0VPQnVJS1k1aFM2dkxkdz09--d615bb61f58bf243d7d949136c2d05d26aaac49a; route=lj-01; login=; lang=en; _ga=GA1.4.1041556506.1557744563; _gid=GA1.4.1289186220.1561356841; _pendo_accountId.029f7ddf-6593-4d82-5a65-a6c66fbf2b5c=AnupamaSoftwareAG; _pendo_visitorId.029f7ddf-6593-4d82-5a65-a6c66fbf2b5c=fldf7517754d071b07cb0e77; _pendo_meta.029f7ddf-6593-4d82-5a65-a6c66fbf2b5c=1358353967; userId=-2; JSESSIONID=CFDB00B95AF1C731356A04B01FF369E3; mp_62107c6714e5356c33d43ef8d8f43cee_mixpanel=%7B%22distinct_id%22%3A%20%22fldf7517754d071b07cb0e77%22%2C%22%24device_id%22%3A%20%2216ab0cfc07a1b8-08fc4f883b46c5-454c062c-1fa400-16ab0cfc07b187%22%2C%22%24initial_referrer%22%3A%20%22%24direct%22%2C%22%24initial_referring_domain%22%3A%20%22%24direct%22%2C%22%24user_id%22%3A%20%22fldf7517754d071b07cb0e77%22%7D; intercom-session-no8pg948=emh3RjRGVzVmczQrTFdUaUZwWWliRTRBaDNlOEtmQ1VHcjh0NWl5eTZPNXVSdHdMU2VjMW9rRmt3WWZ0Q200Mi0tRitFT0Y1dkp6S2cvdkQ5OEFiR3N2Zz09--0f6b176d744b23f9b44bf693c5d9f429f84af84c; _gat_UA-60405455-1=1

If I separate the cookie (like if I send only jssionid it works) but need to send full cookie

Need systax to send this cookie


回答1:


You typically never need to set cookies because Karate will automatically send any cookies returned by the server in the next request. Read the docs: https://github.com/intuit/karate#configure - and you can set multiple cookies the "right way" in Karate like this: https://github.com/intuit/karate#cookie

What you have posted in your question seems to be the entire header made up of multiple cookies. It is most likely that you only need one or two of these for the server you are trying to test. I recommend you check with the team owning the service.

You can set the entire cookies header manually like this if you know what you are doing - but not recommended because of the above reason - and because you will need to handle / encode special characters etc - which is most likely why you ran into issues.

* header Cookie = '_ga=GA1.2.1041556506.1557744563; _gcl_au=1.1.139136457.1560512273; JabmoSP0id.ffef=d37c42bf-f223-43c6-a73c-fa502e23712d.1560512274.5.1561197329.1560589232.2561e1f4-79fe-4b63-88c6-157c6e8ed125; _gid=GA1.2.1289186220.1561356841;'

Note that the right-hand side above can be read from a text file like this:

* header Cookie = read('huge-string.txt') 


来源:https://stackoverflow.com/questions/56792335/how-to-set-big-cookie-header-in-karate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!