Javascript React可以将HttpOnly cookie发送到服务器吗? [英] Can Javascript React send HttpOnly cookie to Server?

查看:224
本文介绍了Javascript React可以将HttpOnly cookie发送到服务器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否使用fetch或通过其他方式将带有HttpOnly cookie的请求发送到React中的服务器?


我知道HttpOnly意味着您无法使用JS访问它。
我在想,也许你看不懂,但可以寄回去?我不知道。


我想要这个:



  • 对服务器的请求是从客户端(ReactJS SPA)发出的

  • 服务器会响应并设置HttpOnly Cookie。

  • 客户端会收到响应,浏览器会自动设置Cookie。


对于同一个服务器有新请求,我想发回该cookie。使用ReactJS有可能吗?
或也许有一些方法可以绕开它,例如使用简单的HTML而不是ReactDOM来打开新窗口?


感谢您的帮助。

解决方案

好,我检查了。


将HttpOnly设置为true的Cookie,仍会发送使用ReactJS,获取或使用JS发出的任何其他请求,您只是无法使用JS读取它,但是使用HttpPost,HttpGet或其他浏览器时,浏览器仍会请求它进行请求,如果它是HttpOnly。 p>

我想这里的教训是浏览器处理为请求设置cookie的情况,它不在乎请求是由HTML还是JavaScript发出的。


Can you, using fetch or by some other means send request with HttpOnly cookie to server in React ?

I know HttpOnly means you can't access it with JS. I'm thinking maybe you can't read it but you can send it back? I don't know.

I want this:

  • Request to server is made from client (ReactJS SPA)
  • Server responds and sets HttpOnly Cookie.
  • Client gets response, cookie is automatically set by browser.

With new request to that same server I want to send back that cookie. is this possible using ReactJS ? or maybe there are some ways to bypass that, like maybe opening new window, with simple HTML, not ReactDOM ?

Thanks for your help.

解决方案

Ok, I checked it out.

Cookie with HttpOnly set with true, will still be send using ReactJS, fetch or any other Request made with JS, You just Can't read it using JS, but when using HttpPost, HttpGet, or other, browser still ataches it to request, event if it's HttpOnly.

I guess the lesson here is that browser handles setting cookies to requests, and it don't care if request is made by HTML, or JavaScript.

这篇关于Javascript React可以将HttpOnly cookie发送到服务器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆