55

タイトルが示すように、アプリケーションがサーバーと通信する iOS プロジェクトで AFNetworking を使用しています。ユーザーがサインインすると、サーバーは成功フラグを返すことで応答し、応答ヘッダーにはセッション ID が含まれます。

AFNetworking が後続のすべてのリクエストでセッション ID を自動的に送信するのか、それとも何らかの方法で自分で処理する必要があるのか​​ 疑問に思っていますか?

参考までに、リクエストがどのように認証されるかに関して、私はバックエンドを制御できません。サーバーと通信するクライアントのみを構築しています。

4

2 に答える 2

116

はい。次のリクエストが送信される前にCookieの有効期限が切れない限り、ログインするとセッションIDが自動的に送信されます(重要な詳細を確認してください)。NSURLConnectionAFNetworkingが使用する、は、このための詳細を自動的に処理します。

バックエンドでは、AFNetworkingが使用しており、セッションを保存するためNSURLConnectionに自動的に更新されます。NSHTTPCookieStorageクッキーストレージをいじることで、適切と思われるクッキーを操作または削除できます。

ログインしていないようにサービスに表示したい場合と同様に、そのドメインに関連付けられているセッションCookieを削除するだけで済みます。すでにログインしていて再度ログインしようとすると、私が使用した一部のサービスでエラーが発生します。さらに、ログインステータスを確認する方法はありませんでした。クイックフィックス、URLからCookieを取得して削除します:

NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL: networkServerAddress];
for (NSHTTPCookie *cookie in cookies) 
{
    [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}

開発者自身から

于 2012-06-14T19:10:02.663 に答える
4

This depends on the specification given by the service you are interacting with. I have worked with similar services and they have explicitly stated in their documentation that, In order to maintain the session valid I must poll the service at every few seconds by sending int "1".

However, If possible could please post the service name or any reference which we can read. If it is any company's private API then they must have described the use of the session id which they are returning.


Underlying technologies will take care of it, However if you want to persist those cookies then this answer for other question.

Persisting Cookies In An iOS Application?

于 2012-06-14T14:27:49.007 に答える