0

Web サイトでユーザー名とパスワードを認証しようとしています...

私は次のように ASIHttpRequest を使用しています:

- (IBAction)fetchTopSecretInformation:(id)sender{
  Ustr = User.text;    //Ustr and Pstr are strings 
  Pstr  = Pass.text;

  NSURL *url1 = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.MySite/login/"]];
  ASIFormDataRequest *request1 = [ASIFormDataRequest requestWithURL:url1];
  [request1 setUseKeychainPersistence:YES];
  request1.delegate = self;
  request1.shouldPresentCredentialsBeforeChallenge = YES;

  [request1 setRequestMethod:@"POST"];
  [request1 setPostValue:User.text forKey:@"username"];
  [request1 setPostValue:Pass.text forKey:@"passwd"];
  [request1 setTimeOutSeconds:30];
  NSLog(@"Useer :%@",User.text);

  [request1 setDidFailSelector:@selector(topSecretFetchFailed:)];
  [request1 setDidFinishSelector:@selector(topSecretFetchComplete:)];
  [request1 startAsynchronous];
}

- (IBAction)topSecretFetchFailed:(ASIHTTPRequest *)theRequest{
  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error sending request to the server" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
  [alert show];
}

- (IBAction)topSecretFetchComplete:(ASIHTTPRequest *)theRequest{
  int statusCode = [theRequest responseStatusCode];
  NSString *statusMessage = [theRequest responseStatusMessage];

  NSString *strResponse = [[theRequest responseString] stringByTrimmingCharactersInSet:    [NSCharacterSet whitespaceAndNewlineCharacterSet]];
  NSString *strFinal = [self flattenHTML:strResponse];
  NSLog(@"Response :%@",strFinal);
  NSLog(@"StatusCode: %d", statusCode);
  NSLog(@"StatusMessage: %@", statusMessage);
}

次のように NSLog で応答を取得します。

jQuery(function($) { $(".main").addClass("show-bg"); });

JavaScript seems to be disabled in your browser.
You must have JavaScript enabled in your browser to utilize the functionality of this website.                

This is a demo store. Any orders placed through this store will not be honored or fulfilled.

                        +995 91 190601

            მოგესალმებით ელექტრონული წიგნების მაღაზიაში 

                        READERwill.com

    კალათა



                        კალათა GEL 0,00
                            სავაჭრო კალათა ცარიელია.

ჩემი ბიბლიოთეკა
სურვილები
რეგისტრაცია

.
.
.
.
.

とステータスコードとステータスメッセージは

StatusCode: 200
StatusMessage: HTTP/1.1 200 OK

この応答とは何ですか。これを認証に使用するにはどうすればよいですか

私のWebサービスでは、ユーザー名とパスワードが正しい場合は「成功」メッセージが表示され、そうでない場合は失敗メッセージが表示されます...

4

3 に答える 3

0

HTTP 200 応答コードは、Web サーバーからの通常の応答です。フォーム認証を使用している場合は、ログインに成功するとセッション Cookie が返されることが予想されるため、応答に設定されている Cookie を調べます。IIRC、ASIHTTPRequest はデフォルトで Cookie を保存し、後続のリクエストで自動的に送信します。

Cookie が設定されていて、その他のエラー状態 (HTTP 401 やその他のエラーなど) が発生しない限り、応答で受信するコンテンツは問題にならない場合がありますが、これは状況に大きく依存しますエラーの応答を解析する必要がある場合があります。この時点で、サーバーが要求のエージェント文字列をスニッフィングして、クライアントが JavaScript をサポートしていないことを検出しているか、JSON で送信されたフォームのようなものを期待していたようです。 AJAX 呼び出しの一部としてフォーマットし、そのスクリプトが失敗したため、JavaScript がブラウザーで正常に実行されていないと想定します (実際にはそうではありません)。

現在username、 とという名前のフィールドpasswdを URL に送信していますhttps://www.MySite/login/

これは Web サービスではなく、Web ページの URL のようです。その URL のログイン ページでログイン フォームを表示する場合、資格情報用の 2 つのフィールドがあり、名前または IDusernameとを使用しますpasswd

<form action="https://www.MySite/login/" method="POST">
    <input name="username" type="text" />
    <input name="passwd" type="password" />
</form>

または:

<form action="https://www.MySite/login/" method="POST">
    <input id="username" type="text" />
    <input id="passwd" type="password" />
</form>

それ以外の場合、SOAP または JSON を介して通信する Web サービスを使用している場合は、URL エンコードされたフォーム データではなく、その形式で認証要求をフォーマットする必要があります。

于 2013-08-06T08:17:50.407 に答える
0
- (IBAction)topSecretFetchComplete:(ASIHTTPRequest *)theRequest
{
    NSString *statusMessage = [theRequest  responseData];
    NSLog(@"StatusCode: %d", statusCode);
    //at this methods you get authuntication
    //write code  here
}
于 2013-08-06T08:05:38.583 に答える