0

簡単なログインシステムを作ろうとしています

私は AFNetworking を使用しています。これが現状のログイン機能です。

- (void) login {

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:email.text, @"email", password.text, @"password", nil];

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://localhost:8888"]];
[httpClient setParameterEncoding:AFFormURLParameterEncoding];

NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST"
                                                        path:@"http://localhost:8888/api.php"
                                                  parameters:params];


AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSString *response = [operation responseString];
    NSLog(@"response: [%@]",response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"error: %@", [operation error]);
}];

[operation start];

}

ステータス 400 の「不正なリクエスト」が返されるため、投稿の形式が正しくないと想定しています。しかし、私はそれの何が悪いのかを見つけることができないようですか?

ログインAPiの概要は次のとおりです

function login() {

    // Check for required params
    if (isset($_POST['email']) && isset($_POST['password'])) { 

        // Put params into local variables
        $email = $_POST['email'];
        $pass = $_POST['password'];

        echo 'Your email:' + $email + 'and password: ' + $password;

        // look up params in db
        $stmt = $this->db->prepare('SELECT `email`, `password`, `group_name` FROM `User` WHERE `email` = ? AND `password` = ?'); 
        $stmt->bind_param('ss', $email, $password); 
        $stmt->execute();
        $stmt->bind_result($u_email, $u_password, $group_name);
        while ($stmt->fetch()) {
            break;
        }

        $stmt->close();

        // Bail if code doesn't exist

        // Return unlock code, encoded with JSON
        $result = array(
            "group_name" => $group_name,
        );

        sendResponse(200, json_encode($result));
        return true;
    } 

    sendResponse(400, 'Invalid request');
    return false;
}  

ご覧のとおり、値が設定されていないため、電子メール/パスワードは投稿と共に送信されていません。

ここでの問題は何ですか?

4

1 に答える 1

1

Web ホストを実行しているマシンで Wireshark を取得します。

http://www.wireshark.org/

次に、サーバーに着信するネットワーク トラフィックを読み取ることができます。

おそらく、サーバーに到達することさえできません。または、ポート 8888 がブロックされている可能性があります。

または、http 要求の形式が正しくなく、サーバーが何をすべきかわからないため、400 を返す可能性があります。

使用できるフィルターについて

tpc.port == 8888

この方法では、ポート 8888 の tcp トラフィックのみが表示されます

于 2012-12-28T23:57:00.910 に答える