0

ASIFormDataRequestを使用してhttp認証済みURLにデータを投稿しています。

認証が失敗し、認証ダイアログデリゲートが呼び出された場合でも、アップロードの進行状況は完全に進行しているように見えます。

したがって、これらの場合:

1)ユーザーのクレデンシャルはまだキーチェーンに保存されていません2)キーチェーンに保存されているユーザーのクレデンシャルは認証に失敗します(期限切れなど)

私はこの振る舞いを見ます:

  • リクエストがサーバーに届き、401拒否エラーがクライアントに返されるのがわかります
  • uploadFailedデリゲートは呼び出されません。
  • ファイルがまだネットワーク接続にプッシュされているように見えるため、プログレスバーデリゲートがゆっくりといっぱいになります。完全にアップロードする時間と一致する時間で完了します
  • 組み込みの認証ダイアログモーダルが表示されます
  • ユーザーが正しいクレデンシャルを入力します
  • プログレスバーデリゲートのリセット
  • アップロードが再開されます-投稿データがサーバーで受信されると、プログレスバーがいっぱいになります
  • 終了したデリゲートメソッドが期待どおりに呼び出されます。
  • この2回目の試行で、すべてが正常にアップロードされました

これが私の操作をセットアップする場所です:

[self setRequest:[ASIFormDataRequest requestWithURL:uploadURL]];

[request setDelegate:self];
[request setDidFailSelector:@selector(uploadFailed:)];
[request setDidFinishSelector:@selector(uploadFinished:)];

[request setUseKeychainPersistence:TRUE];
[request setShouldPresentAuthenticationDialog:TRUE];
[request setShouldPresentCredentialsBeforeChallenge:TRUE];

[request setPostValue:captionTextField.text forKey:@"caption"];
[request setPostValue:[siteID stringValue] forKey:@"site_id"];
[request setFile:fileToUpload forKey:@"site_photo"];

[request setUploadProgressDelegate:progressView];
[request startAsynchronous];

認証に失敗したら[リクエストキャンセル]を発行する必要があると思いますが、どこでやればいいのかわかりません。

サーバーが401を返した後でも、POSTがチャグアウトすることが予想される動作ですか?

これに対処する既存の質問へのガイダンスまたはポインタに感謝します。

4

2 に答える 2

1

401「エラー」はHTTPステータスコードであり、リクエストの失敗ではありません。リクエストは正常に処理され、応答が返されました。これはたまたま認証エラー通知です。それが何であれ、あなたは応答を処理する責任があります。

成功したリクエストから取得できるステータスコードは、401以外にもたくさんあります。余談ですが、エンドユーザーの行動や応答に応じて、こうした種類の応答の処理方法についても検討することをお勧めします。適切な。

通常、メソッド-uploadFinished:は、データが完全にアップロードされるまで待機してからNSLog、リクエストの終了に関するステートメントやその他の通知を表示する必要があります。

したがって、実行する1つのことは、-uploadFailed:および-uploadFinished:メソッド名を変更-requestFailed:-requestFinished:て、アプリケーションのロジックで何が起こっているかをより正確に反映することです。

デリゲートの-requestFinished:メソッドで、のresponseStatusCodeプロパティを確認しrequest、適切なコマンドを発行します。

- (void) requestFinished:(ASIHTTPRequest *)request {
    if ([request responseStatusCode] == 401) {
        //
        // cancel the current request and/or trigger a new, 
        // separate authentication request, passing along a 
        // reference to the request's body data, etc. 
        //
    }
}
于 2010-08-11T23:32:28.407 に答える
0

This is fairly common behaviour for HTTP clients - they do not attempt to read the reply from the server till they have fully sent the request, including the attached file.

It's common behaviour for a client to pre-emptively send the authentication if it has already has a request from the same server rejected with a 401 with in the same session - I am unsure if ASIHTTPRequest does this, but if it does one solution would be to make a GET request to the server before you do the POST. If the GET is successfully authenticated then the cached credentials should be sent for the post and hence there won't be a 401 error.

The only other option I can think of would be to move to cookie based authentication instead, if you are in control of the server, or use authentication in a custom http header. But I think my suggestion of doing a GET request first may be the best approach.

于 2010-08-12T11:41:40.183 に答える