0

I sent a cookie from server side

ResponseBuilder response = Response.ok( (Object) file );
response.header( "Set-Cookie", "fileDownload=test");

I can already view it under the 'Response Header' of the f12 developer tools console. However, document.cookie returns an empty string. The HttpOnly attribute is also unchecked. I'm also not in incognito mode and have cookies enabled. I've already tried changing the localhost address in case it was a web server problem. Is there a way to check the cookie with java script? I just need to check if it has been passed.

Musakkhir Sayyed
  • 7,012
  • 13
  • 42
  • 65
bismarck
  • 1
  • 4
  • can you clear all cookis and then after response come check cookis from all domain and see if it is storing somewhere or not. – Rajesh Kathiriya Jul 27 '16 at 06:44
  • Not sure if setting the Set-Cookie header is the right way to send cookies to client. Please check this: http://stackoverflow.com/questions/28004298/how-to-set-and-check-cookies-wih-jax-rs – Andrés Oviedo Jul 27 '16 at 06:50
  • @Rajesh I cleared the cookies and after calling the service, I can see the Set-Cookie values under Response Header. does that count? – bismarck Jul 27 '16 at 07:10
  • @bismarck can you share the response header from server? – Rajesh Kathiriya Jul 27 '16 at 07:14
  • @Andrés I'm limited to using ResponseBuilder instead of Response that's why... – bismarck Jul 27 '16 at 07:24
  • @Rajesh here is a ss https://s32.postimg.org/rexe3tzol/image.jpg – bismarck Jul 27 '16 at 07:34
  • @bismarck Not sure. But you would probably need to specify the "path" & "domain" parameter. For example / as path and "" as domain. Please check this http://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain – Andrés Oviedo Jul 27 '16 at 08:31
  • @bismarck can set more parameter in set-cookies filed and try, see more cookies field https://curl.haxx.se/rfc/cookie_spec.html and also check cookies of all web domain in browser. – Rajesh Kathiriya Jul 27 '16 at 08:44
  • @Andres I can access the cookie now! It's working in chrome. In addition to adding path and domain, changing the host name from localhost into a valid web server address made it work in IE. Thank you so much to both of you, Andres and Rajesh! – bismarck Jul 28 '16 at 07:02

1 Answers1

-1

Fixed by adding "path" & "domain" parameter.

credits to Andres @bismarck Not sure. But you would probably need to specify the "path" & "domain" parameter. For example / as path and "" as domain. Please check this stackoverflow.com/questions/1134290/… – Andrés

bismarck
  • 1
  • 4