问题
As I know, websites send cookies to browsers for maintaining some state and browser stores it locally. When that website is visited again, browser sends those cookies back to the website as a part of the request. I am under the impression that cookie is a browser-specific thing. I wanted to get this understanding clarified. Can desktop applications which connect to web services support cookies?
We have a web application and we are trying to setup communication from desktop applications such as Adobe apps. For session management I was wondering if we can write an auth token in a cookie if that is supported by desktop apps.
回答1:
Yes, thats very much possible. When you receive the http reply from the server (probably using winhttp or curl) look for the http header 'Set-Cookie' It will be something like
Set-Cookie: name2=value2; Expires=Wed, 09 Jun 2021 10:18:14 GMT
The cookie name is name2 and its value is value2 and it expires on 2021. Store this somewhere in your application context. All the expiry verification has to be done by your application. When you want to make a request with the cookie, set the additional request header 'Cookie'
Cookie: name2=value2
If you are using winhttp WinHttpAddRequestHeaders and WinHttpQueryHeaders calls will be useful to do this task.
来源:https://stackoverflow.com/questions/5674244/cookies-and-desktop-application