1

サイトの認証を処理して UIWebview にロードする必要があるという要件がありました。ネットを検索した後、新しい NSURLConnection を作成し、認証チャレンジを処理しました (リンクのように、UIWebView で認証チャレンジを表示する方法? ) それを使って

すべて正常に動作しますが、次のコードがわかりません。

- (void)connection:(NSURLConnection *)connection
didReceiveResponse:(NSURLResponse *)response
{

        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
        NSString *newUrl = [NSString stringWithFormat:@"%@", response.URL];

        // cancel the connection. we got what we want from the response,
        // no need to download the response data.
        [connection cancel];


        //Start loading the new request in webView
        NSURL *url =[NSURL URLWithString:newUrl];
        NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];

        [webView loadRequest:urlRequest];

}

ここで、webview は、cookie の認証情報を再送信せずに、単にリクエストを再度ロードするだけです。次に、iOS が cookie 管理を自動的に処理することを理解しました。しかし、cookie にアクセスして認証後に印刷しようとすると、何も与えられませんでした。すべての Cookie を取得するためのコードです。

[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]

これはどのように機能しますか?

4

1 に答える 1

0

これは、当時のシミュレーターの問題でした。デバイスでアプリを実行しているときに、Cookie を印刷できました。

于 2013-07-30T06:28:41.573 に答える