Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
139 views
in Technique[技术] by (71.8m points)

javascript - Only include specific cookies in Fetch request

We're trying to use the javascript Fetch api to make requests to the server. While normally we are fine with sending cookies (using the credentials: 'include' option), in this particular use case we want to hit the same api endpoint while not sending all our cookies, but rather just a select few cookies.
Our use case is to allow us to behave anonymously to the api based on our URL parameters on our site. For example, if we go to our site at https://SomeRadSite.com (no idea if that's an actual site, don't go there to find out) we want our cookies to be sent to validate we're logged in and behave as such. But if we go to our site at https://SomeRadSite.com?isAnonymous=true, then we don't want to send all our cookies (only a few) so that any interactions and api calls that take place will all be anonymous.

Again, to summarize the question. Can I selectively choose which cookies (not an all or nothing approach) to send when making a Fetch request?

Edit:

Whether or not the example posted is best practice isn't really the question (that particular code is out of my hands). I'm ultimately trying to discover if I can selectively choose which cookies can be submitted with a fetch request.

question from:https://stackoverflow.com/questions/65602356/only-include-specific-cookies-in-fetch-request

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...