Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

c# - How to set JSON-like cookie from header?

To preface this, I'm still fairly new to requests/cookies/headers so I apologize if something I write doesn't make too much sense.

I'm having an issue with manually setting a cookie that I receive from a response. The issue is when I make the request, the cookie isn't automatically applied but rather it's "stuck" in the Set-Cookie header. So I did my research and found a snippet of code that grabs the value in that response header and adds it to the CookieContainer. The post I followed is here.

Here is a sample of the Set-Cookie header I receive in my responses:

Set-Cookie: auth={"access_token":"e9992200-eae9-4e54-a90a-b0571f8b65f4","token_type":"bearer","expires_in":604799,"scope":"pokemon","role":"PUBLIC","roles":["PUBLIC"]}; path=/; SameSite=Strict; HttpOnly; Secure

Following the code snippet in the linked post, I was expecting to have this cookie set in my next request. However, when I look at my requests using Fiddler, I end up with this. It seems like the code snippet I found doesn't seem to work for a "JSON" type of cookie (if that even makes sense).

How do I make it so that I can grab the "json-like" cookie value from the Set-Cookie header and manually add that to my CookieContainer?

edit 1/20/21: It seems as though when I set the header value to a string and serialize the string into a JSON object, it's almost there. Here is the result of that. It's still not exactly what I need, and even messes up and adds another "role" cookie when it shouldn't be there.


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

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...