在 iPhone 上处理 Cookie 和 Reddit

发布于 2024-09-27 16:48:45 字数 433 浏览 3 评论 0原文

我正在为 iPad 和 iPhone 构建 Reddit 客户端。我知道还有其他一些客户端,但我对选项卡式 Reddit 浏览有一些非常酷的想法 :D

Anywho,我首先在后端工作,并且想知道处理我的 cookie 的最佳方法是什么。我使用 ASIFormDataRequest 和 ASIHTTPRequest 来获取 cookie 并发出对故事和用户 subreddits 的请求。我的问题是,我如何知道 cookie 何时过期并且我不再登录?

一个愚蠢的解决方案(在我看来)是在发出任何类型的数据请求之前再次登录......但这看起来很愚蠢。

另一个解决方案是专门检查对 Reddit 的不同请求的不同响应,并得出我的登录状态。

更好的方法是查看 iPhone 的 cookie 存储中是否有与 Reddit 关联的 cookie,如果没有,请登录。那么,有没有办法做到这一点?

I'm building a Reddit client, for the iPad and the iPhone. I know there's some other clients, but I have some really cool ideas for tabbed Reddit browsing :D

Anywho, I'm working on the back-end of the thing first, and was wondering what the best way to deal with my cookie would be. I'm using ASIFormDataRequest and ASIHTTPRequest to get the cookie and make the requests for stories, and user subreddits. My question is, how do I know when the cookie has expired and I'm not logged in anymore?

A stupid solution (In my opinion) would be to just log in again before making any sort of data request... but that seems, well, stupid.

Another solution would be to check specifically for different responses for different requests to Reddit and derive my logged-in status.

An even BETTER way, would be to somehow see if I have a cookie in the iPhone's cookie store that is associated with Reddit, and if I don't, log in. So, is there a way to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我是有多爱你 2024-10-04 16:48:45

我对 reddit 没有任何具体知识,但是处理此问题的通常方法是发出请求,然后查看是否收到错误消息“未登录”作为响应。

检查存储中是否有 cookie 是可能的,

使用[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[url AbsoluteURL]]

但这不会告诉您 cookie 是否有效 - 它可能在服务器端已过期或者可能在服务器端变得无效 - 因此您仍然需要检查“未登录”错误的响应。 (尽管从 API 文档中可以看出,reddit 仅设置会话 cookie,因此它们永远不会出现在持久存储中 - 在这种情况下,您可以使用 [ASIHTTPRequest sessionCookies] 来查看 cookie。)

I don't have any specific knowledge about reddit, however the usual way to handle this would be to make the request, then see if you got an error saying "Not logged in" as the response.

Checking to see if there is a cookie in the store or not is possible, with

[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[url absoluteURL]]

however this will not tell you if the cookie is valid - it could have been expired on the server side or could have become invalid on the server side - so you will still have to check the responses for "Not logged in" errors. (Although it appears from the API documentation that reddit only sets session cookies, so they'll never appear in the persistent store - in that case you can use [ASIHTTPRequest sessionCookies] to see the cookies.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文