Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在Xcode中创建登录页面?_Iphone_.net_Objective C_Post - Fatal编程技术网

Iphone 如何在Xcode中创建登录页面?

Iphone 如何在Xcode中创建登录页面?,iphone,.net,objective-c,post,Iphone,.net,Objective C,Post,所以我正在创建一个登录页面。但我不确定我在这里错过了什么!每次我尝试登录时,它都会说凭据无效。。。。我打赌我对POST和GET方法感到困惑 任何帮助都将不胜感激!谢谢 我的代码如下: - (IBAction)login:(id)sender { if ([userName.text isEqualToString:@""] || [password.text isEqualToString:@""]) { UIAlertView *alert = [[UIAlertView alloc

所以我正在创建一个登录页面。但我不确定我在这里错过了什么!每次我尝试登录时,它都会说凭据无效。。。。我打赌我对POST和GET方法感到困惑

任何帮助都将不胜感激!谢谢 我的代码如下:

- (IBAction)login:(id)sender {

if ([userName.text isEqualToString:@""] || [password.text isEqualToString:@""]) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oops!" message:@"Please fill in all the fields!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    return;
}

   NSURL *url = [NSURL URLWithString:@"http://WEBSITEHERE/api/users/AuthenticateUser"];
   NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];


NSDictionary *params = @{@"userName": userName.text, @"password": password.text};
NSError *error;
NSData *data = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error];

NSLog(@"PARAMS = %@", params);


[request setHTTPMethod:@"GET"];

[request setValue:@"text/plain" forHTTPHeaderField:@"Accept"];

[request setValue:@"application/json;charset=utf-8" forHTTPHeaderField:@"Content-Type"];

[request setHTTPBody:data];



NSURLResponse *response = nil;


NSData *dataURL = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *result = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];


NSString *responseString = [[NSString alloc]initWithData:dataURL encoding:NSUTF8StringEncoding];



NSLog(@"RESULT = %@", responseString);


    if ([result isEqualToString:@"1"])
    {


        UIStoryboard *mainStoryboard=[UIStoryboard
                                      storyboardWithName:@"MainStoryboard" bundle:nil];

        Home *mainView=[mainStoryboard
                                          instantiateViewControllerWithIdentifier:@"mainView"];

        mainView.modalTransitionStyle=UIModalTransitionStyleCoverVertical;

        [self presentViewController:mainView animated:YES completion:nil];

    }else
    {
        // invalid information
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oops!" message:@"You must have entered something wrong! Try again!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
        return;

    }
}

我不确定您的服务器是如何设置的,但这是我在最近的一个应用程序中设置身份验证请求的方式:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kBaseServerURL, sAuthMethod]]];
[request setHTTPMethod:@"GET"];
[request setValue:_username forHTTPHeaderField:@"j_username"];
[request setValue:_password forHTTPHeaderField:@"j_password"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

对我来说,这看起来像是一个发帖请求。你试过了吗?是的,我把它换成了post。似乎不喜欢我的证书。。。